html.actionlink

发布于 2024-08-05 05:10:57 字数 718 浏览 5 评论 0原文

我刚刚开始使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

冷了相思 2024-08-12 05:10:57

要呈现到 /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}

To render link to /Administration/NewsPublic/7 you should use

<%=Html.ActionLink("Read More..", "NewsPublic", "Administration", 
    New With {.id = 7}, Nothing)%>

Fifth parameter makes compiler to choose

ActionLink(string linkText, string actionName, string controllerName, 
    object routeValues, object htmlAttributes)

extension method overload instead of

ActionLink(string linkText, string actionName, object routeValues, 
    object htmlAttributes)

And don't forget to add parameter assignment

New With {.id = 7}

instead of

New With {.id}
一念一轮回 2024-08-12 05:10:57

默认情况下,Html.ActionLink 将使用当前控制器。但是 ActionLink() 有大约十几个重载,并且有多个版本可以接受控制器参数。尝试:

Html.ActionLink("Read More...", 
                 "NewsPublic", 
                 "Administration",
                 New With { .id = id },
                 null)

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:

Html.ActionLink("Read More...", 
                 "NewsPublic", 
                 "Administration",
                 New With { .id = id },
                 null)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文