該應用程序管理請求。有一個 ActionLink 應該傳入請求的 id,以便它可以被重置。調用了正確的控制器/操作,但請求 ID 始終為空。如果我將自定義路由(如下所示)的最后一個參數更改為 id="TEST",則“TEST”將傳遞到函數中 - 所以我知道選擇了正確的路由。在控制器 BrowseController.cs [HttpGet] public ActionResult ResetRequest(string id ) { return View(); }在 View BrowseRequests.cshtml 中有一個重置請求的鏈接 @Html.ActionLink( "Reset", "ResetRequest", "Browse", new {id = item.RS_RequestID.ToString() });我在 RouteConfig.cs 中嘗試了默認路由,然后嘗試在默認路由之前插入以下內容。 routes.MapRoute( name:"ResetRequest", url:"Browse/ResetRequest/{id}", defaults: new { controller = "Browse", action = "ResetRequest", id=UrlParameter.Optional});
3 回答

慕森卡
TA貢獻1806條經驗 獲得超8個贊
您的 ActionLink 的正確重載是
HtmlHelper.ActionLink(string linkText,string actionName,string ControllerName, object routeValues, object htmlAttributes);
所以您缺少可以作為 null 傳遞的對象 htmlAttributes
@Html.ActionLink("Reset","ResetRequest","Browse", new {id = item.RS_RequestID.ToString() }, null);

猛跑小豬
TA貢獻1858條經驗 獲得超8個贊
您的建議導致“找不到資源”錯誤。這確實讓我想到,也許我為 ActionLink 使用了不正確的簽名。
我發現了一個未指定控制器的覆蓋 - 僅指定了操作。這對我的目的有用
@Html.ActionLink(
"Reset",
"ResetRequest",
new { id = item.RS_RequestID.ToString() });
- 3 回答
- 0 關注
- 139 瀏覽
添加回答
舉報
0/150
提交
取消