7

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

1
  • 1
    What does the URL that gets generated look like? Commented Jun 9, 2012 at 12:13

3 Answers 3

7

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)
Sign up to request clarification or add additional context in comments.

Comments

5

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

Comments

1

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 didn't contain variable names, so it wouldn't be mapped onto your Action parameters.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.