views:

849

answers:

1

The latest MVC release contains some type safe html helper extension methods, for example, CheckBoxFor() and LabelFor() does anyone know if there is a particular reason why they haven't implemented a CheckBoxFor()?

+2  A: 

CheckBoxFor() wasn't finished in time for Beta. It should be available in the next preview release. As for the AddModelErrorFor() overload, there was never any need for it. Errors are supplied by the binders and validators, which use strings rather than expressions. If you can provide a scenario in which using an expression would provide a benefit over simply using strings, we can open a work item for this request.

Levi
Well, I'm not sure, but adding some errors to ModelState in controller action could be handy sometimes, and using AddModelErrorFor() for that would be better than using "magic strings". But if I uderstand correctly, best practise is to handle all the modelstate changes in validators and binders?
PanJanek
You can make modelstate changes in the controller action if you wish; there's nothing inherently wrong with this. But since inside a controller action you've lost some context as to how a model was bound, you can't in general go from an expression back to the string that's equivalent to that expression. For example, should foo => foo.Bar translate as "Bar" or "foo.Bar"? This can get ambiguous quickly.
Levi