2012-04-09 6 views
0

Ich habe eine "Resume" Ansicht, die einen Aufruf an RenderAction macht, so dass ich Kommentare zu einem Lebenslauf hinzufügen kann. Code:RouteData verloren auf Post in einem Controller von RenderAction

Also ruft der Code oben Aktion hinzufügen in meinem ResumeComment-Controller und übergibt es ResumeId. Wenn ich einen Blick auf meine ControllerContext.ParentActionViewContext.RouteData innerhalb des Add (GET) Methode nehmen, sehe ich 4 Werte:

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? 

Antwort

0

Wenn Sie einige Werte in dem Formular ResumeComment.Add stellen müssen Sie sie setzen in versteckte Eingaben. RouteData ist in keiner magischen Weise zwischen Anfragen gespeichert.

0

Sie können die TempData - ihre ähnliche Sitzung verwenden, aber sobald Sie die Daten lesen, ist es gelöscht. Es ist eine gute Lösung, um temporäre Daten zwischen zwei sequentiellen Anfragen zu speichern.