[CLOSED] [RAZOR] Dynamically load contents into Panel

  1. #1

    [CLOSED] [RAZOR] Dynamically load contents into Panel

    I have a layout consisting of 3 panels

            @(                    
                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]
  2. #2
    Hi,

    What about to use the partial views? Here is the example.
    http://forums.ext.net/showthread.php...ll=1#post80510
  3. #3
    Thanks for the reply

    I'm having trouble getting the Partial views to work, getting a NULL pointer exception:

    [NullReferenceException: Object reference not set to an instance of an object.]
       Ext.Net.MVC.PartialViewResult.ExecuteResult(ControllerContext context) +867
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult) +13
       System.Web.Mvc.<>c__DisplayClass1c.<InvokeActionResultWithFilters>b__19() +23
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilter(IResultFilter filter, ResultExecutingContext preContext, Func`1 continuation) +260
       System.Web.Mvc.<>c__DisplayClass1e.<InvokeActionResultWithFilters>b__1b() +19
       System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult) +177
       System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +343
       System.Web.Mvc.Controller.ExecuteCore() +116
       System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +97
       System.Web.Mvc.ControllerBase.System.Web.Mvc.IController.Execute(RequestContext requestContext) +10
       System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +37
       System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +21
       System.Web.Mvc.Async.<>c__DisplayClass8`1.<BeginSynchronous>b__7(IAsyncResult _) +12
       System.Web.Mvc.Async.WrappedAsyncResult`1.End() +62
       System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +50
       System.Web.Mvc.SecurityUtil.<GetCallInAppTrustThunk>b__0(Action f) +7
       System.Web.Mvc.SecurityUtil.ProcessInApplicationTrust(Action action) +22
       System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult) +60
       System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result) +9
       System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +8862381
       System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +184
    Do you have an example of creating a valid PartialView. I'd ideally want to hava a single method in the shared controller instead of the example supplied which has a different Partial render in each controller
  4. #4
    Quote Originally Posted by gets_gui View Post
    Do you have an example of creating a valid PartialView. I'd ideally want to hava a single method in the shared controller instead of the example supplied which has a different Partial render in each controller
    You can set up the PartialViewResult ViewName.

    Here is the modified example.

    Example View
    @{    Layout = "";        
    }
      
    <!DOCTYPE html>
     
    <html>
    <head>
        <title>Ext.NET v2 Example</title>
    </head>
    <body>    
        @Html.X().ResourceManager()
        @(Html.X().Viewport()
            .Layout(LayoutType.Border)
            .Items(items1 =>
            {
                items1.Add(Html.X().MenuPanel()
                    .Title("West")
                    .Region(Region.West)
                    .Width(200)
                    .Menu(menu => 
                    {
                        menu.Add(Html.X().MenuItem()
                            .Text("Load Page 1")
                            .DirectEvents(e =>
                            {
                                e.Click.Url = "/Razor/RenderPartialView/";
                                e.Click.EventMask.ShowMask = true;
                                e.Click.ExtraParams.Add(new Parameter("viewName", "Page1"));
                                e.Click.ExtraParams.Add(new Parameter("containerId", "App.Panel1"));
                                e.Click.Before = "App.Panel1.removeAll()";
                            })   
                        );
                        menu.Add(Html.X().MenuItem()
                            .Text("Load Page 2")
                            .DirectEvents(e =>
                            {
                                e.Click.Url = "/Razor/RenderPartialView/";
                                e.Click.EventMask.ShowMask = true;
                                e.Click.ExtraParams.Add(new Parameter("viewName", "Page2"));
                                e.Click.ExtraParams.Add(new Parameter("containerId", "App.Panel1"));
                                e.Click.Before = "App.Panel1.removeAll()";
                            })     
                        );
                    })
                );
                items1.Add(Html.X().Panel()
                    .ID("Panel1")
                    .Title("Center")
                    .Region(Region.Center)
                    .Layout(LayoutType.Fit));
            })
        )
    </body>
    </html>
    Example Controller Action
    public Ext.Net.MVC.PartialViewResult RenderPartialView(string viewName, string containerId)
    {
        Ext.Net.MVC.PartialViewResult r = new Ext.Net.MVC.PartialViewResult(containerId, RenderMode.AddTo);
        r.ViewName = viewName;
    
        return r;
    }

Similar Threads

  1. [CLOSED] panel icon missing when dynamically load a user control
    By CarpFisher in forum 2.x Legacy Premium Help
    Replies: 5
    Last Post: Jul 30, 2012, 7:47 AM
  2. [CLOSED] [Razor] Setup Auto load panel in razor
    By UnifyEducation in forum 2.x Legacy Premium Help
    Replies: 1
    Last Post: Apr 27, 2012, 10:54 AM
  3. Replies: 3
    Last Post: Feb 21, 2012, 6:40 AM
  4. How to select/copy Panel Contents
    By thedarklord in forum 1.x Help
    Replies: 3
    Last Post: May 25, 2011, 2:36 PM
  5. [CLOSED] ViewPort Panel not sizing to fit contents
    By randy85253 in forum 1.x Help
    Replies: 3
    Last Post: Sep 27, 2008, 3:23 PM

Tags for this Thread

Posting Permissions