I ma using jQuery Ajax request to filter a webgrid and I have several webgrids and several ajax requests. Each Ajax request calls the same ActionResult method but passes different parameters. The idea is the correct method is called based on the parameters I supply. However this doesn’t.
I get this error:
The current request for action 'FilterGrid' on controller type 'UserManagerController' is ambiguous between the following action methods:<br>System.Web.Mvc.ActionResult FilterGrid(Int32, Int32, System.String, System.String, Int32, System.String) on type UserManager.Controllers.UserManagerController<br>System.Web.Mvc.ActionResult FilterGrid(System.String) on type UserManager.Controllers.UserManagerController
My jQuery
function filterGrid() {
var filters = getFilterVals();
$.ajax({
url: '@Url.Action("FilterGrid", "UserManager")',
type: "POST",
async: true,
dataType: "html",
data: "group=" + filters.group,
success: function (data) {
$('#webgrid-wrapper').empty().html(data);
},
error: function (data) {
}
});
}
My Controller code
[HttpPost]
public ActionResult FilterGrid(int alf, int brad, string username, string group, int isactive, string email)
{
List<UserManager.Models.vw_UserManager_Model> modelList = DAL.getGridUsers(alf, brad, username, group, isactive, email);
switch (alf)
{
case 1:
Session["chkBoxAlf"] = 1;
break;
case 0:
Session["chkBoxAlf"] = 0;
break;
}
switch (brad)
{
case 1:
Session["chkBoxBrad"] = 1;
break;
case 0:
Session["chkBoxBrad"] = 0;
break;
}
switch (isactive)
{
case 1:
Session["chkBoxIsActive"] = 1;
break;
case 0:
Session["chkBoxIsActive"] = 0;
break;
}
Session["txtFilterUsername"] = username;
Session["txtFilterGroup"] = group;
Session["txtFilterEmail"] = email;
return PartialView("~/Views/Partial/_WebGridUserManagerUsers.cshtml", modelList);
}
[HttpPost]
public ActionResult FilterGrid(string group)
{
return PartialView("~/Views/Partial/_WebGridUserManagerGroups.cshtml");
}
My breakpoint for
[HttpPost]
public ActionResult FilterGrid(string group)
{
return PartialView("~/Views/Partial/_WebGridUserManagerGroups.cshtml");
}
Doesn’t get hit. Does anyone know how to solve this?
You can’t have two method POST with the same name because the framework don’t know which to call.
But you can configure ActionName:
and in your ajax you call ~/Controller/MethodName