Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>To be more specific, you have to vary it by selection criteria (which might be a verbs change as Darin said, but could also be other selector attributes like NonAction or ActionName). For that matter, you could create your own ActionNameSelectorAttribute derivative to create custom logic indicating when a given method should be used over another.</p> <p>Update: added code per request.</p> <p>I am actually creating a sample ActionMethodSelectorAttribute, b/c I couldn't think of a good usecase for just testing on the name that's not already covered by the ActionNameAttribute. Principle is the same either way, though.</p> <pre><code>public class AllParamsRequiredAttribute : ActionMethodSelectorAttribute { public override bool IsValidForRequest(ControllerContext controllerContext, System.Reflection.MethodInfo methodInfo) { var paramList = methodInfo.GetParameters().Select(p =&gt; p.Name); foreach (var p in paramList) if (controllerContext.Controller.ValueProvider.GetValue(controllerContext, p) == null) return false; return true; } } </code></pre> <p>Basically, this one just gets the names of the params on the action method that it flags, and tests to make sure that the controller's ValueProvider has at least an attempted value of the same name as each. This obviously only works for simple types and doesn't test to make sure the attempted value can cast properly or anyting; it's nowhere close to a production attribute. Just wanted to show that it's easy and really any logic you can return a bool from can be used.</p> <p>This could be applied, then as follows:</p> <pre><code>[AllParamsRequired] public ViewResult Index(int count){/*... your logic ... */} public ViewResult Index() {/*... more of your logic ... */} </code></pre> <p>in this example,and default routing, the url mydomain.com/?count=5 will match the first one, and the url mydomain.com/ will match the second one.</p> <p>Paul</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload