0

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?

6
  • 1
    Can you elaborate more? Commented Jan 24, 2020 at 11:22
  • you can get the element by class, or by name or using general JQuery libraries Commented Jan 24, 2020 at 11:25
  • I don't want to use the class or id , can we get the model object in the javascript? Commented Jan 24, 2020 at 11:27
  • Without additional information (for example) your current code, its hard to tell exactly what you are asking here Commented Jan 24, 2020 at 11:28
  • Does this answer your question? access model in javascript asp .net mvc razor Commented Jan 24, 2020 at 11:39

1 Answer 1

1

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

var model = @Html.Raw(Json.Encode(Model));
Sign up to request clarification or add additional context in comments.

1 Comment

This is how to get the model to the javascript, Now if i will change variable model data then will it reflect on screen?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.