我刚刚开始使用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,我期望它会显示这个url: /Administration/NewsPublic/7,但它给我的是这个url : /Home/NewsPublic?Length=14
actionlink是否只在同一个控制器中传递id?
提前谢谢你!
发布于 2009-09-14 04:11:02
默认情况下,Html.ActionLink将使用当前控制器。但是ActionLink()有十几个重载,并且有多个版本可以接受控制器参数。尝试:
Html.ActionLink("Read More...",
"NewsPublic",
"Administration",
New With { .id = id },
null)发布于 2009-09-14 05:08:00
要呈现到/Administration/NewsPublic/7的链接,您应该使用
<%=Html.ActionLink("Read More..", "NewsPublic", "Administration",
New With {.id = 7}, Nothing)%>第五个参数使编译器选择
ActionLink(string linkText, string actionName, string controllerName,
object routeValues, object htmlAttributes)扩展方法重载而不是
ActionLink(string linkText, string actionName, object routeValues,
object htmlAttributes)别忘了添加参数赋值
New With {.id = 7}而不是
New With {.id}https://stackoverflow.com/questions/1419618
复制相似问题