ASP.NET MVC 3中的@ Html.ActionLink

时间:2022-12-02 11:33:39

My action link in .cshtml is like this:

我在.cshtml中的操作链接是这样的:

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

但只有item.ID的值传递,其他两个值item.Post_ID和item.Reply_ID没有传递..任何人都可以指导我..谢谢..

3 个解决方案

#1


7  

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

看起来你正在为@ Html.ActionLink使用错误的重载:

Try:

尝试:

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

#2


5  

The problem is that when you add in parameter values to an action link you must ALSO add Html Attributes, use this:

问题是,当您将参数值添加到操作链接时,您必须还添加Html属性,使用此:

@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

为Html属性添加Null值将允许发送正确的参数

#3


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.

您的问题是您传递的匿名对象不包含变量名称,因此它不会映射到您的Action参数。

#1


7  

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

看起来你正在为@ Html.ActionLink使用错误的重载:

Try:

尝试:

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

#2


5  

The problem is that when you add in parameter values to an action link you must ALSO add Html Attributes, use this:

问题是,当您将参数值添加到操作链接时,您必须还添加Html属性,使用此:

@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

为Html属性添加Null值将允许发送正确的参数

#3


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.

您的问题是您传递的匿名对象不包含变量名称,因此它不会映射到您的Action参数。