ASP.NET MVC - Filter which action to invoke based on the query string -


I was thinking that it is possible to filter which action is taken based on a parameter in the query string.

For example, I have a grid with a radio button column to select an item in the grid. To edit / delete selected items, the grid is wrapped in one form and at the top of the grid. After clicking on the edit / delete button has been posted back and the jquery magic lacks the magic to set the property so that I can distinguish between an edit and a post. I can then handle it by adding the HPPOST filter feature to my function.

Now I need to add a search to the form. The easiest way for me is to keep the search form out of the current form and get the method. It works but I have a case where the search form should be located within my grid form. I understand that I can not get a nested form, so I removed the form tag for the inner form but now when someone searches, this will trigger a post request. If you are still walking along, you will see that it will remove the verb / deletion method, but I really want to trigger the initial action, but there is an additional search parameter.

Here are the ways my methodology looks like:

  Public Performance Index (String Search) {return GetData (Search); } [HTTPOst] Public Action Result Index (string command, int id) {switch} {case "delete": delitata (id); break; Case "Edit": Return the Redirect Action ("Edit", New {id = id}); } Redirect return action ("index"); }  

Ideally I want to be able to say:

  public performance index (string search) {return GetData (search); } [Command (name = "delete, edit")] or [command (name iisNot = "search")] Public ActionSecult Index (string command, id id) {switch (command) {"delete" Case: Deleted data id); break; Case "Edit": Return the Redirect Action ("Edit", New {id = id}); } Redirect return action ("index"); }  

Note that I can filter which action is brought based on the command. Maybe I have completely confused myself, but MVC is quite new to me and if someone can help you then I would appreciate it.

Thank you

You probably can do this with a route obstacle eg ., I can do something like this:

  Public class commands dialog: IRETE Consultant {# field field private string} matches; # Ndrian # Regional Producer /// & lt; Summary & gt; Starts a new instance of ///; & Lt; Cref = "commandConstraint" /> /// & lt; / Summary & gt; /// & lt; Ultimate name = "matches" & gt; The array of commands to match. & Lt; / Param & gt; Public Command Contrast (parameter string [] matches) {match = matches; } #endrian # area law /// & lt; Summary & gt; /// determines whether this hindrance is /// & lt; / Summary & gt; /// & lt; Ultimate name = "context" & gt; Current reference. & Lt; / Param & gt; /// & lt; Ultimate name = "route" & gt; Way to test & Lt; / Param & gt; /// & lt; Param name = "name" & gt; Name of the parameter. & Lt; / Param & gt; /// & lt; Param name = "values" & gt; Route value. & Lt; / Param & gt; /// & lt; Ultimate name = "direction" & gt; Direction of the route & Lt; / Param & gt; /// & lt; Returns & gt; It is true when it is bound, otherwise wrong & Lt; / Returns & gt; Public Bull Match (HTTPTextExtbase Reference, Route Route, String Name, Root Valuation Value, Router Direction Direction) {If (matches == blank) return false; String value = value [name]. Ostring (); Fresh (String match in matches) {If (string. Eccles (match, value, string commerment. Inventory culture Ignore case)) returns true; }          return false; } #endregion}  

And then on my routes such programs:

  routes. MapRoute ("search", "home / {command}", new {controller = "home", action = "index", command = UrlParameter.Optional}, new {command = new CommandConstraint ("search")}); Routes MapRoute ("Other", "Home / {Command} / {ID}", New {Admin = "Home", Action = "Index", Command = URL Parameters. Optional, ID = UrlParameter.Optional}, New {command = New command dialog ("delete", "edit")});  

Obviously you will need to change your index (...) functions so that the parameter names are both "commands", but at least you should help in the right direction?


Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -