im trying to update data in javascript via viewmodel.
When the side loads it works.
window.addEventListener('load', function () {
let listModel = @Html.Raw(Json.Serialize(Model));
LoadAllInfoSpots(listModel);
});
But when i call my js function
function afterClickOnFlorplan() {
setTimeout(function () {
let listModel [email protected](Json.Serialize(Model));
LoadAllInfoSpots(listModel);
}, 1500);
}
the let listmodel
is the same as when i loaded the side. with a count of 4.
i know the viewmodel is updating.
but as you can see let listmodel
is not updated in my js code.
So why is the let listmodel
the same all the time?
hope you can help me.
Model:
public class SelectorModel
{
public int? ID { get; set; }
public string ImageName { get; set; }
public string Cords { get; set; }
public string Name { get; set; }
}
ViewModel:
public class SelectorViewModel
{
public List<SelectorModel> SelectorModels { get; set; }
}
the first IActionResult:
public IActionResult Index()
{
LoadInfoSpotsFromDB load = new LoadInfoSpotsFromDB();
string first = load.LoadFirstImage();
SetFirstIMageCookie(first);
List<SelectorModel> loaede = load.Load(first);
selectorViewModel = new SelectorViewModel
{
SelectorModels = loaede
};
return View(selectorViewModel);
}
the IActionResult
that update the ViewModel
[HttpPost]
public IActionResult Index([FromBody] string dontremove)
{
selectorViewModel = null;
LoadInfoSpotsFromDB load = new LoadInfoSpotsFromDB();
List<SelectorModel> loaede = load.Load(HttpContext.Request.Cookies["ImageName"]);
selectorViewModel = new SelectorViewModel
{
SelectorModels = loaede
};
return View(selectorViewModel);
}