Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

83
Views
MVC core 5.0 update js via Viewmodel

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 =@Html.Raw(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. pic of the viewmodel updatede

but as you can see let listmodel is not updated in my js code.

old listmodel

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);
        }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!