PDA

View Full Version : [CLOSED] [2.1] MVC Partial View



softmachine2011
Aug 22, 2012, 1:47 PM
Hi,

I'm trying to load a mvc partial view with parameters that returns a usercontrol, and I'm unable to do it. I do that in v1.x.

This is my test case:

MAIN VIEW


<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<%@ Register Src="~/Views/Shared/UserControl.ascx" TagName="Control" TagPrefix="custom" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title>Ext.NET Example</title>
</head>
<body>
<form runat="server">
<ext:ResourceManager runat="server" />
<custom:Control runat="server" />
</form>
</body>
</html>


USERCONTROL


<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<ext:Panel ID="MyPanel" runat="server" Layout="FitLayout" Title="Panel with partial view" Height="500">
<Loader runat="server" Url="/Area/Sample/MyPartialView">
<LoadMask ShowMask="true" Msg="Custom loagind message..." UseMsg="true" />
<Params>
<ext:Parameter Name="containerId" Value="#{MyPanel}" Mode="Value" />
<ext:Parameter Name="dummy" Value="(new Date()).getTime()" Mode="Raw" />
</Params>
</Loader>
</ext:Panel>


CONTROLLER (dummy parameter is not collected)


public ActionResult MyPartialView(string containerId)
{
return new Ext.Net.MVC.PartialViewResult(containerId, Ext.Net.RenderMode.AddTo);
}


PARTIAL VIEW USERCONTROL


<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<dynamic>" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

<ext:Label runat="server" Text="Partial View Label" />


I tried to change Mode property of Loader to Frame, Html, Script but i wasn't lucky.

How I have to load a mvc partial view in Ext.NET 2.1?

Thanks

Daniil
Aug 22, 2012, 2:43 PM
Hi,

You can set up

Scripts="true"
for the loader, but the recommended Mode to render partial views is Script (instead of default Html).

<Loader runat="server" Mode="Script">

In that case you should set up WrapByScriptTag to false for a PartialViewResult.

Also set up SingleControl to true if you need the Label to participate in layout logic.

Example

public ActionResult MyPartialView(string containerId)
{
Ext.Net.MVC.PartialViewResult r = new Ext.Net.MVC.PartialViewResult(containerId, Ext.Net.RenderMode.AddTo);
r.SingleControl = true;
r.WrapByScriptTag = false;
return r;
}

softmachine2011
Aug 23, 2012, 7:48 AM
It works with this properties (Mode="Script" and Scripts="true") in loader and changes in controller

Thanks!

Daniil
Aug 23, 2012, 7:55 AM
Scripts="true"
should not be required with

Mode="Script"
if you set up

r.WrapByScriptTag = false;

softmachine2011
Aug 23, 2012, 1:04 PM
Scripts="true"
should not be required with

Mode="Script"
if you set up

r.WrapByScriptTag = false;

Yes, you are right!