1

Can somebody tell me what is wrong with this ActionLink?

@Html.ActionLink(posts.Title, "PostDetails", "Blogs", new { id = posts.PostID } )

I am expecting this link to go to:

http://localhost/Blogs/PostDetails?whateverpassed

But instead I see the following in Firefox:

http://localhost:1815/Home/PostDetails?Length=5

It's not even going to Blogs controller.

Andrew Whitaker
  • 124,656
  • 32
  • 289
  • 307
patel.milanb
  • 5,822
  • 15
  • 56
  • 92

2 Answers2

2

Are you sure you are calling the right overloaded method. If you miss one param it gives a different meaning.

HTML.ActionLink method

http://msdn.microsoft.com/en-us/library/dd505040.aspx

Please double check if you are missing a param.

Community
  • 1
  • 1
Mangesh
  • 3,987
  • 2
  • 31
  • 52
  • well, that link sorted out everything... i have to provide the last parameter in ActionLink... @Html.ActionLink(posts.Title, "PostDetails", "Blogs", new { id = posts.PostID }, null ) – patel.milanb Sep 10 '11 at 19:52
  • 2
    I often make this same mistake. Your original code is using `routeValues = "Blogs", htmlAttributes = new {id = posts.PostId} `because it's the wrong overload. – Scott Rippey Sep 10 '11 at 20:12
1

It has to do with the way the route values are passed, use this instead:

 @Html.ActionLink(posts.Title, "PostDetails", new {Controller="Blogs", id = posts.PostID } )
Turnkey
  • 9,266
  • 3
  • 27
  • 36