Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@Html.ActionLink in ASP.NET MVC 3

My action link in .cshtml is like this:

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

and my method in controller is like this:

[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 value of item.ID is getting passed, other two values item.Post_ID and item.Reply_ID are not getting passed.. Can anyone please guide me.. thanks..

like image 864
vijay yaragall Avatar asked Jun 09 '12 11:06

vijay yaragall


2 Answers

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)
like image 173
Darren Avatar answered Sep 22 '22 23:09

Darren


The problem is that when you add in parameter values to an 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 the Null value for Html Attributes will allow the correct parameters to be sent

like image 21
CD Smith Avatar answered Sep 23 '22 23:09

CD Smith