我有一个“简历”视图,它调用 RenderAction,以便我可以在简历中添加评论。代码:
@{Html.RenderAction("Add", "ResumeComment", new { resumeId = @Model.Id });}
所以上面的代码在我的 ResumeComment 控制器中调用 Add action 并将它传递给 resumeId。如果我查看 Add (GET) 方法中的 ControllerContext.ParentActionViewContext.RouteData,我会看到 4 个值:
PL <- which is resume category
954 <- resume id
Resume <- Controller
Edit <- Action, because I am adding comments on the Edit page in the resume.
The problem that I have is that I am loosing resume category (PL) and resume id(954) when I post (add a comment). Here is my ResumeComment form:
@using (Html.BeginForm("Add", "ResumeComment"))
{
...
<input type="submit" value="Add Comment" />
..}
So this form will call Add (Post) method in the ResumeComment controller when sumitted. Here is my add method:
[HttpPost, ActionName("Add")]
public ActionResult Add(ResumeComment resumeComment)
{
.....
}
I am not able to access ControllerContext.ParentActionViewContext.RouteData at all, it is null. I am however able to access ControllerContext.RouteData but when I look at the values I only see "ResumeComment" and "Add" in there and that is it. How can I preserve the resume category and resume id?