2012-04-09 43 views
0

我有一個「Resume」視圖,它調用RenderAction,以便我可以向簡歷添加註釋。代碼:RouteData在由RenderAction調用的控制器中發佈郵件時丟失

@{Html.RenderAction("Add", "ResumeComment", new { resumeId = @Model.Id });} 

所以上面調用的代碼添加動作在我ResumeComment控制器,並將其傳遞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

如果你想在你的表來發表一些值ResumeComment.Add你需要將它們放在隱藏的輸入。 RouteData並沒有以任何神奇的方式在請求之間持續存在。

0

您可以使用TempData - 類似的會話,但是一旦您讀取它的數據就會被刪除。 它是在兩個連續請求之間存儲臨時數據的一個很好的解決方案。

相關問題