c# - ASP.NET MVC ambiguous action methods -


I have two verb methods that are disputed. In fact, I want to be able to use two different routes of the same scene, either by the item's ID or by the name of the item and its parents (only one of the different parents of the objects may name).

  item / {action} / ParentName / itemName item / {action} / 1234- A search term can be used to filter the list.  

4321-1234-4321

These are my verb methods (here are remove action methods too ...)

  / / Method # 1 Assign a Public Action Rialit (string parentName, string itemName) {// logic here to identify the item ... string itemId = ...; Return Redirect Action ("Assign", "Item", New {itemId}); } // Method # 2 Assign Public Action Result (String IITID, String SearchTerm, Int page) {...}  

And there are routes ...

  routes MapRoute ("AssignRemove", "item / {action} / {itemId}", new {controller = "item"}); Routes.MapRoute ("AssignRemovePretty", "item / {action} / {parentName} / {itemName}", new {controller = "item"});  

I understand why the error is happening, because the page parameter may be redundant, but I can not understand the best way to solve it. Is my design bad? I have thought of expanding the signature of method # 1 to include a search parameter in method # 2 to exclude a private method, but they Both will call, but I do not believe that in reality, the ambiguity will solve.

Any help would be greatly appreciated.


Original Solution (Based on Levi's Answer)

I added the following category ...

  Requirements for the public categoryOARTAviewAttribute: Action Methodspector Attribute {Public RequirementOverviewAutvanced (string [] Wellname) {ValueNames = valueNames; } Public override bund isValidForRequest (Controller Contents Controller, MethodInfo methodInfo) {bool contains = false; Forex currency (value value in value names) {Contains = Controlling Consort. Risen Constant RoutData value. (Value) of canteen; If (! In it) breaks! } Is included in the return; } Public string [] ValueNames {get; Private set; }}  

and then the action methods were decorated ...

  [RequireRouteValues ​​(new [] {"parentName", "itemName"} )] Assign Public ActionResult (string parentName, string itemName) {...} [RequireRouteValues ​​(new [] {"itemId"})] Assign Public ActionResult (string itemId) {...}  

MVC does not fully support the method on signature, therefore it will fail: < / P>

  Public Action Rachelle Mammoth (Int. Some INIT) {/ * ... * /} in Public ActionCartsult Python (string some strings) {/ * ... * /}  

However, it does support method of overloading based on attribution:

In the above example, the attribute says only, "This method matches if the key xxx was present in the request." If you believe your goals are better, then you can also filter by the information contained in the route (Fearless Controller Reference).


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -