[英]The current request for action 'AdminManagement' on controller type 'AdminController' is ambiguous between the following action methods
[Route("admins")]
public ActionResult AdminManagement()
{
EmployeeBuslayer lstEmp = new EmployeeBuslayer();
AdminManamegemtModel comModel = new AdminManamegemtModel();
comModel = lstEmp.GetAdminsWithRole;
return View(comModel);
}
#region AdminMaster
[HttpPost]
[ActionName("AdminManagement")]
public ActionResult AdminManagementPost()
{
string SearchText = Request.Form["Search"].ToString().ToLower();
EmployeeBuslayer lstEmp = new EmployeeBuslayer();
List<AdminMaster> dataEmployee = null;
AdminManamegemtModel comModel = new AdminManamegemtModel();
AdminManamegemtModel comModelfromDB = lstEmp.GetAdminsWithRole;
dataEmployee = comModelfromDB.AdminMasterModel.Where(src => src.UserName.ToLower().Contains(SearchText) || src.EmailID.ToLower().Contains(SearchText)).ToList();
comModel.AdminMasterModel = dataEmployee;
comModel.AdminRoleMasterModel = comModelfromDB.AdminRoleMasterModel;
return View("AdminManagement", comModel);
}
above two methods are for same view. 以上两种方法是针对同一观点的。 and i have search button . 我有搜索按钮。 when clicked on search it gives me below error. 当点击搜索时,它给了我下面的错误。
The current request for action 'AdminManagement' on controller type 'AdminController' is ambiguous between the following action methods: System.Web.Mvc.ActionResult AdminManagementPost() on type MVCAdminDemo.Controllers.AdminController System.Web.Mvc.ActionResult AdminManagement() on type MVCAdminDemo.Controllers.AdminController. 在以下操作方法之间,当前对控制器类型“ AdminController”的操作“ AdminManagement”的请求是模棱两可的:类型为MVCAdminDemo.Controllers.AdminController的System.Web.Mvc.ActionResult AdminManagementPost()System.Web.Mvc.ActionResult的AdminManagement()键入MVCAdminDemo.Controllers.AdminController。 I can solve this error by removing ActionName from AdminManagementPost() , but problem is URL changes and i dont want that . 我可以通过从AdminManagementPost()中删除ActionName来解决此错误,但是问题是URL发生了更改,我不希望那样。 url shoud be
http://localhost:52499/admin/admins
网址应为http://localhost:52499/admin/admins
AdminManagement() is Get method loads on load default AdminManagement()是默认在加载时获取方法加载
I think action name does not matter here. 我认为动作名称在这里无关紧要。 As you have not specified any http verb for the first action method, it is considered as post. 由于您没有为第一个操作方法指定任何http动词,因此将其视为post。 SO whenever you are trying to call this route, it is ambiguous as two action methods with verb post are available on same route. 因此,每当您尝试调用此路线时,它都是模棱两可的,因为在同一条路线上有两种带动词发布的操作方法。 Decorate the first action method with [HttpGet] as it seems like a get action. 用[HttpGet]装饰第一个action方法,因为它看起来像是get操作。 sample code below: 下面的示例代码:
[Route("api/datasync/get")]
[HttpGet]
public IHttpActionResult GetOne()
{
return Ok(1);
}
[Route("api/datasync/get")]
[HttpPost]
public IHttpActionResult GetOnes()
{
return Ok(1);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.