【发布时间】:2017-10-25 18:10:51
【问题描述】:
[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);
}
以上两种方法用于相同的视图。我有搜索按钮。当点击搜索它给我下面的错误。
当前对控制器类型的“AdminManagement”操作请求 'AdminController' 在以下操作方法之间不明确: System.Web.Mvc.ActionResult AdminManagementPost() 类型 MVCAdminDemo.Controllers.AdminController System.Web.Mvc.ActionResult MVCAdminDemo.Controllers.AdminController 类型上的 AdminManagement()。一世 可以通过从 AdminManagementPost() 中删除 ActionName 来解决此错误 ,但问题是 URL 更改,我不希望那样。网址应该是
http://localhost:52499/admin/admins
AdminManagement() 是 Get 方法在加载时加载的默认值
【问题讨论】:
标签: c# url model-view-controller routing attributerouting