我想从PartialView中访问ID的路由值。我有一个帖子,评论场景。我希望我的评论partialview有权访问PostId。在部分视图中访问Id的路由值
的URL看起来如下:
帖子/详细信息/ 2
现在,我怎么能访问局部视图里面的值2?
UPDATE:
我改变了我的CommentsController以下几点:
public ActionResult Add(string id,string subject,string name,string body)
{
}
但现在当我调试它甚至没有踏进Add方法。
更新2:
我的部分观点如下所示:
<div class="title">Add Comment</div>
@using (Html.BeginForm("Add","Comments",FormMethod.Post))
{
@Html.Label("Subject")
@Html.TextBox("subject")
<br />
@Html.Label("Name")
@Html.TextBox("name")
<br />
@Html.Label("Body")
@Html.TextBox("body")
<input type="submit" value="submit" />
}
这里是控制器:
public ActionResult Add(string id, string subject, string name, string body)
如果我从上面的控制器动作删除ID,然后在它作品。
反正从CommentsController内获取它还是我去取的评论视图中,然后把它放在隐藏字段,并将其发布到CommentsController的作用? – johndoe 2011-06-16 18:35:37
@johndoe,如果你想在某个控制器上获取它,只需将其作为参数传递给action:'public ActionResult Foo(string id){...}'并且模型联编程序应该负责传递它。 – 2011-06-16 18:36:40
@Darin Dimintrov我已经更新了我原来的问题。 – johndoe 2011-06-16 18:45:44