Reputation: 1615
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
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
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