加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – 具有多个参数的ActionLink

发布时间:2020-12-15 18:51:28 所属栏目:asp.Net 来源:网络整理
导读:我想使用我的ActionLink创建一个像/?name = Macbeth year = 2011的URL,我已经尝试过这样: %= Html.ActionLink("View Details","Details","Performances",new { name = item.show },new { year = item.year })% 但它不工作。我如何做到这一点? 解决方法
我想使用我的ActionLink创建一个像/?name = Macbeth& year = 2011的URL,我已经尝试过这样:
<%= Html.ActionLink("View Details","Details","Performances",new { name = item.show },new { year = item.year })%>

但它不工作。我如何做到这一点?

解决方法

您使用的重载使年值在链接的html属性中结束(检查渲染源)。

过载签名看起来像这样:

MvcHtmlString HtmlHelper.ActionLink(
    string linkText,string actionName,string controllerName,object routeValues,object htmlAttributes
)

你需要把你的路由值放入RouteValues字典,像这样:

Html.ActionLink(
    "View Details",new { name = item.show,year = item.year },null
)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读