Benk
Benk

Reputation: 1312

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.

Upvotes: 9

Views: 71649

Answers (3)

Paola Puchetta
Paola Puchetta

Reputation: 1

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

Upvotes: -1

Jakub Konecki
Jakub Konecki

Reputation: 46008

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

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

Upvotes: 24

James McConnell
James McConnell

Reputation: 2198

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.

Upvotes: 7

Related Questions