2017-04-21 58 views
0

請求URL無效項:http://localhost:51536/Employee/AddUpdateEmployee/2參數字典包含參數 '僱員'

路由配置

public static void RegisterRoutes(RouteCollection routes) 
{ 
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

    routes.MapRoute(
     name: "Default", 
     url: "{controller}/{action}/{id}", 
     defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
    ); 
} 

控制器的操作方法

[ActionName("AddUpdateEmployee"), HttpGet] 
public ActionResult AddUpdate(Int64 EmployeeID) 
{ 
    var data = (new EmployeeDb()).GetEmployee(EmployeeID); 
    return View("~/Views/Employee/_AddUpdateView.cshtml", data); 
} 

當我檢查在瀏覽器中的URL,我得到這個錯誤:該p arameters詞典共包含參數無效項「僱員」

回答

0

,這是因爲根據你的路線,當你做/2它認爲它作爲/{id}值意味着id,動作中的參數名稱是EmployeeID所以這將是null

解決方案1:

public ActionResult AddUpdate(Int64 EmployeeID) 

變化到

public ActionResult AddUpdate(Int64 id) 

解決方案2:

發送值等

http://localhost:51536/Employee/AddUpdateEmployee?EmployeeID=2

相關問題