开发者

asp.net mvc client side validation for camel case property name

I am using the MS shipped client side validation in asp.net mvc 2. The model in question has one property called "FirstName". Our client side developer really like to have camel-case in the elements id, so instead of using the normal html helper Html.TextBoxFor(m => m.FirstName), we wrote out the html input view instead like: <input type="text" id="firstName" name="firstName" />. The model binder can bind correctly and get the right valud ( I guess it was not case sensitive, which is a good thing). However, when we turn on client side valuation and issue a Html.ValidateFor(m => m.FirstName) at the end, it still generates the Pascal-case format of the property (which is expected).

I look into the mvc 2 source code reveils that ValidateFor() calls ModelMetadata.FromLambdaExpression(expression, htmlHelper.ViewData) which in turn uses MemberExpression to get the property name (which is pascal case).开发者_开发百科 I am wondering if there is way around this? The ultimate goal is to have camel-case ID is the elements of the html and still have both client and server side validation works.

Any help is appreciated.


My $0.02: Pick a casing and make the view model match the page. Both C# and JS are case-sensitive, and attempting to mix cases won't end well. One of you is going to have to change case. You could probably work around this specific issue, but it won't be the end of your problems.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜