MVC3 razor remote validation - Controller argument

2019-07-28 05:37发布

问题:

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.