简体   繁体   English

MVC & Url.Action

[英]MVC & Url.Action

Hi I am having difficulties using Url.Action method, please see my code below, what am I doing wrong....?嗨,我在使用Url.Action方法时遇到困难,请参阅下面的代码,我做错了什么......? (I'm using MVC Razor) (我正在使用 MVC Razor)

<a href='<%: @Url.Action("Edit", "Student", 
    new { id = item.DealPostID }) %>'>Hello          </a>

Student is my StudentController and Edit is ActionResult method. Student是我的StudentControllerEditActionResult方法。

Remove <%: %> from your Razor view.从 Razor 视图中删除<%: %> Those are WebForms tags.这些是 WebForms 标签。

<a href='@Url.Action("Edit", "Student", 
    new { id = item.DealPostID })'>Hello          </a>

Try this:试试这个:

@Html.ActionLink("Hello", "Edit", "Student", new { id = item.DealPostID }, null)
  • Argument 1: Link text参数 1:链接文本
  • Argument 2: Action name参数 2:动作名称
  • Argument 3: Controller name参数 3:控制器名称
  • Argument 4: Route values参数 4:路由值
  • Argument 5: HtmlAttributes.参数 5:HtmlAttributes。 This is set to null so that it doesn't append "?Length=" to your URL.这被设置为 null 以便它不会将“?Length=”附加到您的 URL。

That should work out for you.那应该适合你。

 <a href='@Url.Action("Index", "Cliente", "Home")'>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM