I was wondering if it is possible to filter which action is called based on paramater in the query string.
For example, I have a grid with a switch column to select an item in the grid. The grid is wrapped in a shape, and at the top of the grid are buttons for editing / deleting the selected element. Pressing the edit / delete buttons returns messages and makes it impossible to use jquery magic to set the command property, so I can distinguish between editing and message. Then I can handle this by adding the HttpPost filter attribute to my action.
Now I need to add a search to the form. The easiest way to do this is to place the search form outside the existing form and set the receiving method. This works, but I have a case where the search form should be located in my grid form. I understand that I do not have nested forms, so I deleted the form tags for the internal form, but now when I perform a search, it calls for a submit request. If you still follow, you will see that this calls the edit / delete method, but I really want to initiate the initial action, but you have an additional search parameter.
Here's what my action methods look like:
public ActionResult Index(string search)
{
return GetData(search);
}
[HttpPost]
public ActionResult Index(string command, int id)
{
switch (command)
{
case "Delete":
DeleteData(id);
break;
case "Edit":
return RedirectToAction("Edit", new { id = id });
}
return RedirectToAction("Index");
}
Ideally, I would like to say:
public ActionResult Index(string search)
{
return GetData(search);
}
[HttpPost]
[Command(Name="Delete,Edit")] OR [Command(NameIsNot="Search")]
public ActionResult Index(string command, int id)
{
switch (command)
{
case "Delete":
DeleteData(id);
break;
case "Edit":
return RedirectToAction("Edit", new { id = id });
}
return RedirectToAction("Index");
}
, , . , , MVC , , - .