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

367
Views
Update ASP.NET MVC Model value from javascript

In an ASP.NET MVC page, I'd like to change some valuee in the Model from javascript code when I click on an onClick button event.

I tried several solution but in any case the model is updated.

As exemple : In the model there are :

  • Firstname
  • LastName
  • Email.

In the razor page :

@Html.TextboxFor(model => model.LastName, new { id = "MyLastName" })

There is a button :

<button id="btnDelete" onclick="/*Code to update model*/ ">Click me</button>

In "Code to update model", I'd like change the model value for @Model.FirstName and @Model.Email via javascript.

I tried to assign Model.LastName to an HiddenFor :

@Html.HiddenFor(model => model.Lastname, new { id = "MyLastName" })

Get the value by javascript and change the value but the value in the Model is not updated.

Any idea ?

Thanks

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!