How to change model property from javascript function inside view?


Is there a way to change model properties from a javascript function inside a view?

In particular, I have an edit view and you need to access the value of the row property with

Function SomeJSFunction () {
var somevar = '<% = Model.Property%>';
...

then make some changes to somevar and set the model property to the changed line. I feed at this point, so it’s not a matter of handling the display, you just need to change the model from within the function before I submit. I know that I can pass the string as a parameter and process it inside the controller, but it just doesn’t shorten it, since I really need to do this in the view. Appreciate any help!

+4
source share
1 answer

You cannot do this using javascript. The model is created by the controller instance and goes to the view. If you want to change some properties, you will need to fulfill a request to the controller action and send new values. This can be done either using a standard form or an AJAX request.

+5
source

All Articles