[CLOSED] Ext.Net.Mvc partial view result & MVC 3 doesn't seem to work

  1. #1

    [CLOSED] Ext.Net.Mvc partial view result & MVC 3 doesn't seem to work

    I am having trouble getting to work a simple app that uses the Ext.Net.MVC.

    Please test it using version 1.5 of Ext.Net and Ext.Net.MVC.

    The app is very simple, it shows a combobox populated with the country names. When I select a country I want to display a panel using a PartialViewResult. The problem is that the app displays the string Ext.Net.MVC.PartialViewResult instead of rendering the content of the control.

    I tried to follow the Ext.Net.MVC demo and I added a button as well but nothing happens as well. I included all the source code. Maybe I am missing some setting.

    Thanks

    Code:

    Test.aspx:
    <%@ Page Language="C#" %>
    
    <%@ Register assembly="Ext.Net" namespace="Ext.Net" tagprefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
        
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.NET Example</title>
       <ext:ResourcePlaceHolder ID="ResourcePlaceHolder1" runat="server" />
       <script type="text/javascript">
         
         function selectRow(item,record,index) {
           //alert(record.get('TableName'));
    //       Ext.Ajax.request({
    //         url: '/TestDynamicGridPanel/Home/TableGridPanelView',
    //         method: 'POST',
    //         params: {
    //           'containerId': 'SqlTable'
    //
    //         },
    //         success: function (result, request) {
    //           debugger;
    //           eval(eval(result.responseText));
    //
    //         },
    //
    //         failure: function (result, request) {
    //           alert(result);
    //         }
    //       });
           
           
         }
         
       </script>
       
       
    
    </head>
    <body>
        <ext:ResourceManager ID="ResourceManager" runat="server"  ScriptMode="Debug" SourceFormatting="true" IDMode="Client"/>
        
        <ext:Store 
          ID="DataTableStore" 
          runat="server">
          <Reader>
              <ext:JsonReader>
                  <Fields>
                      <ext:RecordField Name="TableName" Type="String" />
                  </Fields>
              </ext:JsonReader>
          </Reader>
        </ext:Store>
                
        <ext:Viewport runat="server" Layout="fit">
          <Items>
            <ext:Panel runat="server" Layout="fit" id="Panel1">
              <TopBar>
                <ext:Toolbar runat="server">
                  <Items>
                    <ext:ComboBox 
                        ID="SqlTablesComboBox" 
                        runat="server" 
            
                        Mode="Local"
                        Width="300"
                        >
                      <Items>
                        <ext:ListItem Text="Belgium" Value="BE" />
                        <ext:ListItem Text="Brazil" Value="BR" />
                        <ext:ListItem Text="Bulgaria" Value="BG" />
                        <ext:ListItem Text="Canada" Value="CA" />
                        <ext:ListItem Text="Chile" Value="CL" />
                        <ext:ListItem Text="Cyprus" Value="CY" />
                        <ext:ListItem Text="Finland" Value="FI" />
                        <ext:ListItem Text="France" Value="FR" />
                        <ext:ListItem Text="Germany" Value="DE" />
                        <ext:ListItem Text="Hungary" Value="HU" />
                        <ext:ListItem Text="Ireland" Value="IE" />
                        <ext:ListItem Text="Israel" Value="IL" />
                        <ext:ListItem Text="Italy" Value="IT" />
                        <ext:ListItem Text="Lithuania" Value="LT" />
                        <ext:ListItem Text="Mexico" Value="MX" />
                        <ext:ListItem Text="Netherlands" Value="NL" />
                        <ext:ListItem Text="New Zealand" Value="NZ" />
                        <ext:ListItem Text="Norway" Value="NO" />
                        <ext:ListItem Text="Pakistan" Value="PK" />
                        <ext:ListItem Text="Poland" Value="PL" />
                        <ext:ListItem Text="Romania" Value="RO" />
                        <ext:ListItem Text="Slovakia" Value="SK" />
                        <ext:ListItem Text="Slovenia" Value="SI" />
                        <ext:ListItem Text="Spain" Value="ES" />
                        <ext:ListItem Text="Sweden" Value="SE" />
                        <ext:ListItem Text="Switzerland" Value="CH" />
                        <ext:ListItem Text="United Kingdom" Value="GB" />                    
                      </Items>
                      <Listeners>
                        <Select Handler="#{Panel1}.load( { scripts: true, params: { containerId: 'SqlTable' }, url: '/TestDynamicGridPanel/Test/MyPartialView' });"></Select>
                      </Listeners>
                    </ext:ComboBox>
                    <ext:Button ID="mybutton" Text="Hit Me">
                      <DirectEvents>
                         <Click Url="/TestDynamicGridPanel/Test/TableGridPanelView">
                            <ExtraParams>
                                <ext:Parameter Name="containerId" Value="SqlTable" Mode="Value" />
                            </ExtraParams>
                        </Click>
                      </DirectEvents>
                    </ext:Button>
                  </Items>
    
                </ext:Toolbar>
              </TopBar>
              <Content>
                  <div id="SqlTable">
                  </div>
              </Content>
            </ext:Panel>
          </Items>
        </ext:Viewport>
    </body>
    </html>
    TableGridPanelView.ascx:
    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <script runat="server">
      protected void Page_Load(object sender, EventArgs e)
      {
        throw new Exception("blah blah blah");
      }
    
    </script>
    <ext:Panel ID="Panel" 
        runat="server" 
        Title='<%# ViewData["title"] %>' 
        Border="false" 
        Html='<%# ViewData["html"] %>' 
        AutoDataBind="true"
        />
    web.config:
    <?xml version="1.0" encoding="utf-8"?>
    <!--
      For more information on how to configure your ASP.NET application, please visit
      http://go.microsoft.com/fwlink/?LinkId=152368
      -->
    <configuration>
      <configSections>
        <section name="extnet" type="Ext.Net.GlobalConfig" requirePermission="false" />
      </configSections>
      <appSettings>
        <add key="webpages:Version" value="1.0.0.0" />
        <add key="ClientValidationEnabled" value="true" />
        <add key="UnobtrusiveJavaScriptEnabled" value="true" />
      </appSettings>
      <system.web>
        <compilation debug="true" targetFramework="4.0">
          <assemblies>
            <add assembly="System.Web.Abstractions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add assembly="System.Web.Helpers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add assembly="System.Web.Routing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add assembly="System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
            <add assembly="System.Web.WebPages, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
          </assemblies>
        </compilation>
        <authentication mode="Forms">
          <forms loginUrl="~/Account/LogOn" timeout="2880" />
        </authentication>
        <pages>
          <namespaces>
            <add namespace="System.Web.Helpers" />
            <add namespace="System.Web.Mvc" />
            <add namespace="System.Web.Mvc.Ajax" />
            <add namespace="System.Web.Mvc.Html" />
            <add namespace="System.Web.Routing" />
            <add namespace="System.Web.WebPages" />
          </namespaces>
          <controls>
            <add tagPrefix="ext" namespace="Ext.Net" assembly="Ext.Net" />
          </controls>
        </pages>
        <httpHandlers>
          <add path="*/ext.axd" verb="*" type="Ext.Net.ResourceHandler" validate="false" />
        </httpHandlers>
        <httpModules>
          <add name="DirectRequestModule" type="Ext.Net.DirectRequestModule, Ext.Net" />
        </httpModules>
      </system.web>
      <system.webServer>
        <modules runAllManagedModulesForAllRequests="true">
          <add name="DirectRequestModule" preCondition="managedHandler" type="Ext.Net.DirectRequestModule, Ext.Net" />
        </modules>
        <validation validateIntegratedModeConfiguration="false" />
        <handlers>
          <add name="DirectRequestHandler" verb="*" path="*/ext.axd" preCondition="integratedMode" type="Ext.Net.ResourceHandler" />
          <add name="ExtNetHandler" path="*/ext.axd" verb="*" type="Ext.Net.ResourceHandler"/>
        </handlers>
      </system.webServer>
      <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
            <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
            <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.8.0" />
          </dependentAssembly>
        </assemblyBinding>
      </runtime>
      <extnet theme="Default" />
    </configuration>
    Global.asax.cs:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using System.Web.Routing;
    
    namespace TestDynamicGridPanel
    {
      // Note: For instructions on enabling IIS6 or IIS7 classic mode, 
      // visit http://go.microsoft.com/?LinkId=9394801
    
      public class MvcApplication : System.Web.HttpApplication
      {
        public static void RegisterGlobalFilters(GlobalFilterCollection filters)
        {
          filters.Add(new HandleErrorAttribute());
        }
    
        public static void RegisterRoutes(RouteCollection routes)
        {
          routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
    
          routes.IgnoreRoute("{exclude}/{extnet}/ext.axd");
    
          routes.MapRoute(
              "Default",                                              // Route name
              "{controller}/{action}/{id}",                           // URL with parameters
              new { controller = "Home", action = "Index", id = "" }  // Parameter defaults
          );
    
          /**/
    
          routes.MapRoute(
            "Default2",
            "{controller}.mvc/{action}/{id}",
            new { action = "Index", id = "" }
          );
    
          routes.MapRoute(
            "Root",
            "",
            new { controller = "Home", action = "Index", id = "" }
          );
    
    
        }
    
        protected void Application_Start()
        {
    
          AreaRegistration.RegisterAllAreas();
    
          RegisterGlobalFilters(GlobalFilters.Filters);
          RegisterRoutes(RouteTable.Routes);
        }
      }
    }
    MyPartialView.ascx:

    <%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    
    <ext:Panel ID="Panel1" runat="server" Layout="Accordion" Border="false">
        <Items>
            <ext:Panel ID="Panel2" runat="server" Title="Item1" />
            <ext:Panel ID="Panel3" runat="server" Title="Item2" />
            <ext:Panel ID="Panel4" runat="server" Title="Item3" />
            <ext:Panel ID="Panel5" runat="server" Title="Item4" />
            <ext:Panel ID="Panel6" runat="server" Title="Item5" />
        </Items>
    </ext:Panel>
    TestController.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using Ext.Net;
    
    
    namespace TestDynamicGridPanel.Controllers
    {
        public class TestController : Controller
        {
            //
            // GET: /Home/
            public ActionResult Test()
            {
              return View();
            }
    
            public ActionResult TableGridPanelView(string containerId)
            {
              Ext.Net.MVC.PartialViewResult pr = new Ext.Net.MVC.PartialViewResult(containerId);
              pr.RenderMode = RenderMode.RenderTo;
              pr.SingleControl = true;
              pr.WrapByScriptTag = false;
              
              pr.ViewData["title"] = DateTime.Now.ToLongTimeString();
              pr.ViewData["html"] = DateTime.Now.ToLongTimeString();
    
              return pr;
            }
    
          public ActionResult MyPartialView(string containerId)
          {
            Ext.Net.MVC.PartialViewResult pr = new Ext.Net.MVC.PartialViewResult(containerId);
            return pr;
          }
    
        }
    }
    Last edited by Daniil; Jul 16, 2012 at 11:03 PM. Reason: [CLOSED]
  2. #2
    I just wanted to add that I ultimately want to be able to render on the fly GridPanels whose columns vary (depending on the selection) and are data driven. Using MVC partial view results seems like good option to achieve this. If you have other recommendations please point me to that sample or post some code.

    Thank you
  3. #3
    Hi,

    Using the partial views looks to be the best option in your case.

    As far as I set up
    Layout="fit"
    for the Panel1 you expect the partial view will be stretched up to that panel, right?

    Please note any Layout deals with Items only, not with Content.

    I would apply the following changes regarding the MyPartialView rendering.

    1. Remove
    <Content>
        <div id="SqlTable">
        </div>
    </Content>
    2. Replace
    containerId: 'SqlTable'
    with
    containerId: 'Panel1'
    3. The controller action is:
    public ActionResult MyPartialView(string containerId)
    {
        Ext.Net.MVC.PartialViewResult pr = new Ext.Net.MVC.PartialViewResult(containerId);
        pr.RenderMode = RenderMode.AddTo;
        pr.SingleControl = true;
        return pr;
    }
    In this case the MyPartialView will be rendered ok and participate in the layout logic.
  4. #4
    I made the change that you suggested and it still doesn't work.

    Again, the Response Body for the controller method returns "Ext.Net.MVC.PartialViewResult" instead of all JavaScript code that renders the control (I used the IE Developer tools to view the traffic).

    I am not too sure what's wrong here. I recompiled to Ext.Net.MVC dll with .Net 4 and MVC 3.0, but it's still doing this.

    Any ideas?

    Thanks

    Just an update: I modified the Ext.Net.MVC.Demo project to use asp.net mvc 3 and now the Examples -> Partial Views sample stopped working.

    It is as if the ExecuteResult method of Ext.Net.MVC.PartialViewResult object is not invoked.
  5. #5
    If the Ext.NET has been built with MVC 2 (I think our released dlls are built with MVC 2), but you use these dlls with MVC 3, you should add a respective assemblyBinding item into the Web.config, redirecting MVC 2 to MVC 3.

    Hope this helps.
  6. #6
    Quote Originally Posted by Daniil View Post
    If the Ext.NET has been built with MVC 2 (I think our released dlls are built with MVC 2), but you use these dlls with MVC 3, you should add a respective assemblyBinding item into the Web.config, redirecting MVC 2 to MVC 3.
    Never mind, I answered in haste. I see you said that compiled with MVC 3 and the assemblyBinding is already within the Web.config.

    Could you email a whole test project with the dlls, please?
    daniil at ext dot net
  7. #7
    I have emailed you the project file.
  8. #8
    You have wrong 'assemblyBinding' section in web.config
    Please remove 'Newtonsoft.Json' binding
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
          <dependentAssembly>
               <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
               <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
          </dependentAssembly>
    </assemblyBinding>
    or move it inside another 'dependentAssembly' section
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
                <dependentAssembly>
                    <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
                    <bindingRedirect oldVersion="1.0.0.0-2.0.0.0" newVersion="3.0.0.0" />
                </dependentAssembly>
    
    
                <dependentAssembly>
                    <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
                    <bindingRedirect oldVersion="1.0.0.0-4.0.0.0" newVersion="4.0.8.0" />
                </dependentAssembly>
            </assemblyBinding>
  9. #9
    That did the trick, thank you!

Similar Threads

  1. [CLOSED] Partial View Error
    By peter.campbell in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Feb 10, 2012, 10:32 AM
  2. Javascript not work in partial view mvc.ext.net
    By theblackcat_2902 in forum 1.x Help
    Replies: 9
    Last Post: Aug 24, 2011, 10:31 AM
  3. [CLOSED] RegisterOnReadyScript in MVC partial view
    By SandorD in forum 1.x Legacy Premium Help
    Replies: 22
    Last Post: Aug 10, 2011, 4:17 PM
  4. Replies: 1
    Last Post: Dec 22, 2010, 2:46 PM
  5. Replies: 6
    Last Post: Feb 15, 2010, 9:15 AM

Posting Permissions