html.actionlink
我刚刚开始使用 asp.net mvc.. 因为我不熟悉它,我只是想问一个关于actionlink html helper的问题..
我的index.aspx主视图中有这段代码..
<% Dim _news As datatable = ViewData.Model%>
<% For count As Integer = 0 To _news.Rows.Count - 1%>
<% Dim id As Integer = _news.Rows(count).Item("IDnews")%>
<%=_news.Rows(count).Item("newsTitle")%>
<p>
<%=_news.Rows(count).Item("newsContent")%><br />
<%=Html.ActionLink("Read More..", "NewsPublic", "Administration", New With {id})%>
</p>
<%Next%>
如果我单击actionlink,我希望它会让我看到这个网址: /管理/新闻公共/7 但它给了我这个网址: /Home/NewsPublic?Length=14
actionlink 仅在同一控制器中传递 id 吗?
先感谢您!
i'm just starting to use asp.net mvc..
since i'm not familiar with it, i just want to ask a question about actionlink html helper..
i have this code in my index.aspx home view..
<% Dim _news As datatable = ViewData.Model%>
<% For count As Integer = 0 To _news.Rows.Count - 1%>
<% Dim id As Integer = _news.Rows(count).Item("IDnews")%>
<%=_news.Rows(count).Item("newsTitle")%>
<p>
<%=_news.Rows(count).Item("newsContent")%><br />
<%=Html.ActionLink("Read More..", "NewsPublic", "Administration", New With {id})%>
</p>
<%Next%>
if i click the actionlink, i was expecting it will render me to this url:
/Administration/NewsPublic/7
but rather it gives me this url :
/Home/NewsPublic?Length=14
does actionlink pass id in the same controller only?
thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要呈现到 /Administration/NewsPublic/7 的链接,您应该使用
第五个参数使编译器选择
扩展方法重载而不是
并且不要忘记添加参数分配
而不是
To render link to /Administration/NewsPublic/7 you should use
Fifth parameter makes compiler to choose
extension method overload instead of
And don't forget to add parameter assignment
instead of
默认情况下,Html.ActionLink 将使用当前控制器。但是 ActionLink() 有大约十几个重载,并且有多个版本可以接受控制器参数。尝试:
By default, Html.ActionLink will use the current controller. But there are about a dozen overloads of ActionLink(), and there are multiple versions of it that will accept a controller parameter. Try: