Nebojsa Veron
Nebojsa Veron

Reputation: 1615

Modify ViewModel property value through Javascript in MVC3

Is it possible to change a property value from a ViewModel using javascript?

For example:

<script type="text/javascript">
        @Model.PageNumber = 2;
</script>

Upvotes: 3

Views: 3192

Answers (2)

Judah Gabriel Himango
Judah Gabriel Himango

Reputation: 60001

No; that page code is executed once; changing the model wouldn't do anything even if it was allowed.

If you want a view model that can change on the client-side, and have the UI automatically update in response to changes, KnockoutJS is what you're looking for. With KnockoutJS, you can have view models with properties that can be changed in javascript, and the UI will automatically update accordingly.

Upvotes: 0

rick schott
rick schott

Reputation: 20617

No, JavaScript is on the client-side(unless you are using Node.js), and MVC3 Views are rendered on the server-side in the Controllers.

Upvotes: 2

Related Questions