I know it's possible to change view representation of any .NET type by changing strongly-typed partial view. The most popular example is when simple ToString() call on DateTime instance is changed to a great-looking JQuery UI calendar.
My question is - how does ASP.NET MVC know what property of JavaScript control to use when binding to a property of a view model? Is there a convention for that (or at least Phil Haack post about it)? If it is, both ASP.NET MVC and JS library requires some kind of rule, or only one side?
views:
17answers:
1
+1
A:
The model binder knows nothing about javascript. When binding action parameters it looks at the request sent to the server and binds properties using conventions. Scot Hanselman blogged about some advanced binding conventions used by the binder.
Darin Dimitrov
2010-10-21 09:02:28
so if I use another control (let's say, JQuery slider to override Int32 appearance) it will work just fine? no need to add extra logic?
chester89
2010-10-21 09:11:02
No need to add any logic. As long as you send for example `Value=1234` in the query string or post body, no matter what GUI widget you used, the default model binder will set the `Value` property of your model to `1234`.
Darin Dimitrov
2010-10-21 09:12:25
Perhaps the problem here is that somehow this extra js control is not putting data in the post or get. If you expect this to happen when you submit a form, check the docs for the js control, some require you to issue a commit or save command on the js control before it will post with a form.
CrazyDart
2010-10-21 22:19:50