Jul 04, 2012, 12:24 PM
[CLOSED] [RAZOR] Dynamically load contents into Panel
I have a layout consisting of 3 panels
I've not able to get the content of the mainPanel to render. I've tried (as the example) below to update the content of the panel but this doesnt work.
@(
Html.X().Viewport()
.ID("ViewPort")
.Layout(Ext.Net.LayoutType.Border)
.Items(items =>
{
items.Add(Html.X().Panel()
.ID("launcher")
.Title("Launcher")
.Collapsible(true)
.Region(Region.West)
.Weight(10)
.Items(buttons =>
{
buttons.Add(Html.X().Button()
.ID("homeButton")
.Text("Home")
.DirectEvents(directEvents =>
{
directEvents.Click.Url = "/Shared/OnAppLaunched";
directEvents.Click.ExtraParams.Add(new Parameter()
{
Name = "uri",
Value = "~/Views/Home/Index.cshtml",
Mode = ParameterMode.Value
});
}));
buttons.Add(Html.X().Button()
.ID("app1Button")
.Text("App1")
.DirectEvents(directEvents =>
{
directEvents.Click.Url = "/Shared/OnAppLaunched";
directEvents.Click.ExtraParams.Add(new Parameter()
{
Name = "uri",
Value = "~/Views/App1/Index.cshtml",
Mode = ParameterMode.Value
});
}));
}));
items.Add(Html.X().Panel()
.ID("control1Panel")
.Title("Control1")
.Collapsible(true)
.Region(Region.North)
.Height(90)
.ItemsFromPage(this, "~/Views/Shared/_Control1.cshtml"));
items.Add(Html.X().Panel()
.ID("mainPanel")
.Region(Region.Center)
.ItemsFromPage(this, "~/Views/App1/Index.cshtml"));
})
)
I've written a method in the shared controller which is called by each of the button clicks. Which sends a URL to be rendered in the mainPanel.I've not able to get the content of the mainPanel to render. I've tried (as the example) below to update the content of the panel but this doesnt work.
public ActionResult OnAppLaunched(string uri)
{
string msg = ""; //= X.Msg.Alert("DirectEvent URI: ", "Value is [" + uri + "]").ToScript();
var mainPanel = X.GetCmp<Panel>("mainPanel");
var filePath = HttpContext.Server.MapPath(uri);
var content = new WebClient().DownloadString(filePath);
// Using RazorEngine to parse the cshtml document before sending the results to the mainPanel
var newContent = RazorEngine.Razor.Parse(content, new { Name = "content"});
mainPanel.ClearContent();
mainPanel.Update(newContent, true);
return new AjaxResult(msg);
}
Last edited by Daniil; Jul 10, 2012 at 11:25 AM.
Reason: [CLOSED]