RemoteAttribute in viewmodel and ActionNameAttribute in corresponding action method (MVC3)

320 Views Asked by At

I just discovered that remote validation using the RemoteAttribute will not work unless either:

  1. The action method for the remote validation does not have an [ActionName] attribute, or
  2. The action method for the remote validation has an [ActionName] attribute that is a case-insensitive match for the actual action method name.

With the following, MVC throws an InvalidOperationException "No url for remote validation could be found.":

[ActionName("validate-my-widget")]
public virtual JsonResult ValidateMyWidget(string value1, string value2) 
{
...
}

Any idea why? I am using T4MVC if that makes a difference.

1

There are 1 best solutions below

0
On BEST ANSWER

What is the action name which you are supplying in the Remote attribute?

If you are supplying the name of your action method (as opposed to the name declared in the ActionName attribute), then the VirtualPathProvider will generate a URL using the underlying action method's name. If you supply the name declared in the ActionName attribute, then the URL will be generated using the method name declared in the ActionName attribute.