我有一个“恢复”视图,它调用了RenderAction,因此我可以在简历中添加注释。代码:
@{Html.RenderAction("Add", "ResumeComment", new { resumeId = @Model.Id });}
所以上面的代码在我的ResumeComment控制器中调用Add动作并传递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?
答案 0 :(得分:0)
如果您想将表单中的某些值发布到ResumeComment.Add
,则需要将它们放入隐藏的输入中。 RouteData
在请求之间不存在任何神奇的方式。
答案 1 :(得分:0)
您可以使用TempData - 类似会话,但一旦您从中读取数据就会被删除。 它是在两个连续请求之间存储临时数据的好方法。