4

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()?

1
  • And I'm also courious why where is no ModelState.AddModelErrorFor(expression, msg) method to add some high level validation errors to model state in controller. Commented Dec 10, 2009 at 17:21

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

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?
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.