简体   繁体   English

在以下操作方法之间,当前对控制器类型“ AdminController”的操作“ AdminManagement”的请求不明确

[英]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.

相关问题 在以下操作方法之间,当前对控制器类型“ ...”的操作请求[…]不明确 - The current request for action […] on controller type '…' is ambiguous between the following action methods 控制器类型&#39;WeeklyTargetController&#39;上的当前动作&#39;Create&#39;请求在以下操作方法之间是不明确的: - The current request for action 'Create' on controller type 'WeeklyTargetController' is ambiguous between the following action methods: 路由:当前的动作请求 […] 在以下动作方法之间是不明确的 - Routing: The current request for action […] is ambiguous between the following action methods 控制器类型{1}上的当前操作请求{0}不明确 - The current request for action {0} on controller type {1} is ambiguous 控制器类型为{x}的当前操作请求{x}模棱两可 - The current request for action {x} on controller type {x} is ambiguous MVC异常:以下操作方法之间存在歧义 - MVC Exception: Ambiguous between the following action methods 在以下操作方法之间请求歧义 - Request ambiguos between the following action methods Create 控制器中的MVC5模糊动作方法 - MVC5 ambiguous action methods in controller 控制器的动作在具有相同名称的基类的动作之间是不明确的。 - The controller's action is ambiguous between the action of the baseclass with same name. AmbiguousMatchException:行动要求不明确 - AmbiguousMatchException: Request for action is ambiguous
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM