简体   繁体   中英

MVC & Url.Action

Hi I am having difficulties using Url.Action method, please see my code below, what am I doing wrong....? (I'm using MVC Razor)

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

Student is my StudentController and Edit is ActionResult method.

Remove <%: %> from your Razor view. Those are WebForms tags.

<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
  • 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.

That should work out for you.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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