0

我有一个“简历”视图,它调用 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?
4

2 回答 2

0

您可以使用TempData - 类似会话,但一旦您从中读取数据,就会被删除。在两个顺序请求之间存储临时数据是一个很好的解决方案。

于 2012-04-09T20:01:11.453 回答
0

如果您想在表单中发布一些值,则ResumeComment.Add需要将它们放入隐藏输入中。RouteData在请求之间不会以任何神奇的方式持续存在。

于 2012-04-09T19:54:45.307 回答