asp.net-mvc MVC & Url.Action
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8100528/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MVC & Url.Action
提问by Benk
Hi I am having difficulties using Url.Actionmethod, please see my code below, what am I doing wrong....? (I'm using MVC Razor)
嗨,我在使用Url.Action方法时遇到困难,请参阅下面的代码,我做错了什么......?(我正在使用 MVC Razor)
<a href='<%: @Url.Action("Edit", "Student",
new { id = item.DealPostID }) %>'>Hello </a>
Studentis my StudentControllerand Editis ActionResultmethod.
Student是我的StudentController,Edit是ActionResult方法。
回答by Jakub Konecki
Remove <%: %>from your Razor view. Those are WebForms tags.
<%: %>从 Razor 视图中删除。这些是 WebForms 标签。
<a href='@Url.Action("Edit", "Student",
new { id = item.DealPostID })'>Hello </a>
回答by James McConnell
Try this:
尝试这个:
@Html.ActionLink("Hello", "Edit", "Student", new { id = item.DealPostID }, null)
- Argument 1: Link text
- Argument 2: Action name
- Argument 3: Controller name
- Argument 4: Route values
- Argument 5: HtmlAttributes. This is set to null so that it doesn't append "?Length=" to your URL.
- 参数 1:链接文本
- 参数 2:动作名称
- 参数 3:控制器名称
- 参数 4:路由值
- 参数 5:HtmlAttributes。这被设置为 null 以便它不会将“?Length=”附加到您的 URL。
That should work out for you.
那应该适合你。
回答by Paola Puchetta
<a href='@Url.Action("Index", "Cliente", "Home")'>

