@ Html.ActionLink in ASP.NET MVC 3

My action in .cshtml looks like this:

@Html.ActionLink("Reply", "Post_Reply", new { item.ID, item.Post_ID, item.Reply_ID }) 

and my method in the controller is as follows:

 [Authorize] public ActionResult Post_Reply(int PostId=0, int Id = 0, int ReplyId = 0) { post posts = new post(); posts.ID = Id; return View(posts); } 

but only the value of item.ID gets the value, the other two values ​​of item.Post_ID and item.Reply_ID are not passed. Can anyone advise me .. thanks ..

+7
source share
3 answers

It looks like you are using the wrong overload for @Html.ActionLink :

Try:

 @Html.ActionLink("Reply", "Post_Reply", new { Id = item.ID, PostId = item.Post_ID, ReplyId = item.Reply_ID }, null) 
+7
source

The problem is that when you add parameter values ​​to the action link, you must also add HTML attributes, use this:

 @Html.ActionLink("Reply", "Post_Reply", new { Id = item.ID, PostId = item.Post_ID, ReplyId = item.Reply_ID }, null) 

Adding a Null value for Html attributes will allow you to send the correct parameters

+5
source

Try

 @Html.ActionLink("Reply", "Post_Reply", new { Id = item.ID, PostId = item.Post_ID, ReplyId = item.Reply_ID }) 

Your problem was that the anonymous object you passed in does not contain variable names, so it will not display on your action parameters.

+1
source

All Articles