为了账号安全,请及时绑定邮箱和手机立即绑定

ActionLink 参数始终为 null - 即使使用自定义路由

ActionLink 参数始终为 null - 即使使用自定义路由

C#
慕妹3146593 2022-11-22 10:22:04
该应用程序管理请求。有一个 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);


查看完整回答
反对 回复 2022-11-22
?
猛跑小猪

TA贡献1858条经验 获得超8个赞

您的建议导致“找不到资源”错误。这确实让我想到,也许我为 ActionLink 使用了不正确的签名。


我发现了一个未指定控制器的覆盖 - 仅指定了操作。这对我的目的有用


    @Html.ActionLink(

      "Reset", 

      "ResetRequest", 

      new { id = item.RS_RequestID.ToString() });


查看完整回答
反对 回复 2022-11-22
?
开满天机

TA贡献1786条经验 获得超12个赞

您传递给 ActionLink 的值的顺序不正确

使用操作、控制器、路由值、htmlArguments

你的第一个参数应该是 ResetRequest


查看完整回答
反对 回复 2022-11-22
  • 3 回答
  • 0 关注
  • 89 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信