MVC3 razor remote validation - Controller argument is always empty

非 Y 不嫁゛ 提交于 2020-01-15 09:08:08

问题


I can call the controller but the argument (string) is always null.

All the examples I have found name the controller argument the same as the property we are validating remotely, sounds good/easy, but if you look at fiddler what is really being passed in is the name attribute from the input statement. Well that is problematic in that it is a subscripted name something like Person.EMailAddresses[0].Address, well I can't name my controller parameter like that.

So how do I get around this? There must be a way to specify the controllers parameter name in the remote() attribute?


回答1:


It cannot be done using the default RemoteAttribute. This is a link to an example I posted of a reusable remote validation attribute, where you can specify the name of the controller, action and the name of the variable used to pass the value to the action.



来源:https://stackoverflow.com/questions/7328605/mvc3-razor-remote-validation-controller-argument-is-always-empty

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!