Anirudh Agarwal
Anirudh Agarwal

Reputation: 11

Set the model property in MVC using the javascript function

There is a scenario where I want to update the Model with which the .cshtml page is binded, using javascript. I do not want to use the document.getElementById.

Can we achieve this using javascript?

Upvotes: 0

Views: 408

Answers (1)

Sara Pahlevani
Sara Pahlevani

Reputation: 11

To solve your issue, instead of document.getElementById you could use

var model = @Html.Raw(Json.Encode(Model));

Upvotes: 1

Related Questions