PDA

View Full Version : [CLOSED] ViewBag and Razor



zwf
Nov 28, 2012, 1:54 PM
Hi there,

I want to open a window, which is a partial view, the following way :


public ActionResult RenderES_EINSATZExportWindow(ExportOptionenWindow exoptionen)
{
return new Ext.Net.MVC.PartialViewResult { ViewName = "WindowEinsaetzeExport", Model = aModel};
}

which works fine, buuuuut :
I want additional data to be passed to this window, which is not part of the model.
I thought of adding a ViewBag :



public ActionResult RenderES_EINSATZExportWindow(ExportOptionenWindow exoptionen)
{
ViewBag.test = "Test";
return new Ext.Net.MVC.PartialViewResult { ViewName = "WindowEinsaetzeExport", Model = aModel};
}



Html.X().TextField().ID("hidden_RW_NR").Hidden(true).Value(@ViewBag.test)

but the viewbag seems not to be visible in the window.

I thought of adding this data from the viewbag to hidden fields in the window.

Regards,
Holger

zwf
Nov 28, 2012, 2:09 PM
I think, I'll try it with cookies.
Setting the cookies in the backing code
and getting these values whenever I need them.



public void createCookie(String cookieName, String cookieValue)
{
HttpCookie cookie = new HttpCookie(cookieName);
cookie.Value = cookieValue;
this.ControllerContext.HttpContext.Response.Cookie s.Add(cookie);
}




public String getCookieValue(String cookieName)
{
String cookieRDBValue = this.HttpContext.Request.Cookies[cookieName].Value;
return cookieRDBValue;
}

Vladimir
Nov 28, 2012, 2:21 PM
Just pass ViewData to PartialViewResult


return new Ext.Net.MVC.PartialViewResult { ViewName = "WindowEinsaetzeExport", Model = aModel, ViewData = ViewData};


or use


return this.PartialExtView("WindowEinsaetzeExport", aModel);


The behaviour the same as with standard PartialViewResult

zwf
Nov 28, 2012, 2:27 PM
Just pass ViewData to PartialViewResult


return new Ext.Net.MVC.PartialViewResult { ViewName = "WindowEinsaetzeExport", Model = aModel, ViewData = ViewData};


or use


return this.PartialExtView("WindowEinsaetzeExport", aModel);


The behaviour the same as with standard PartialViewResult

OK, that's the way.
But I have to pass this data again to a directevent from the window.
This is kind of a wizard, where I pass data from window to window.



.DirectEvents(de =>
{
de.Click.Url = Url.Action("DirectEventSaveExportGridClicked");
de.Click.ExtraParams = @ViewData......??? <----- how to set the viewdate here ???

in Razor ......


But the cookieway isn't so bad, because I can use this data everywhere in the backing code

Daniil
Dec 03, 2012, 11:31 AM
Hi Holger,

This should work.

de.Click.ExtraParams.Add(new {name = ViewData.Value});