PDA

View Full Version : [CLOSED] MVC - Loading UserControl's with PartialViewResult



ontiv
Jun 13, 2013, 12:35 PM
Hi @all,

I load on clientside with jscript UserControls in Asp - Repeater.

Here some code snippets to understand the situation.

.js


var p_new_item = new Ext.Panel({
id: name_control,
layout: 'fit',
border: false
});

var p_loader = new Ext.Panel({
id: name_loader,
border: false,
hidden: true,
loader: {
url: url,
disableCaching: true,
scripts: true,
params: {
containerId: p_new_item.id,
contSID: contSID
}
}
});

p_list.add(p_loader);
p_list.add(p_new_item);


.Controller.cs


public ActionResult uc_ContText(string containerId, string contSID)
{

this.ViewData["contSID"] = contSID;

var pr = new Ext.Net.MVC.PartialViewResult(containerId);
pr.ViewData = ViewData;
pr.RenderMode = Ext.Net.RenderMode.AddTo;
pr.SingleControl = true;
pr.IDMode = Ext.Net.IDMode.Explicit;

return pr;
}


That works with a UserControl (.ascx) which was developed with Ext.Net but not with UserControl with Asp-Code.
If I build a ext:Panel around the asp-div, it works too!

.ascx


<ext:Panel runat="server">
<Content>
<div>
//My UserContol.....
</div>
</Content>
</ext:Panel>


How I can Asp-UserControls load without Ext.Net -Code ??
Thanks!

Daniil
Jun 13, 2013, 1:29 PM
Hi @ontiv,

I think you cannot use these options:

pr.RenderMode = Ext.Net.RenderMode.AddTo;
pr.SingleControl = true;
if a partial view contains native ASP.NET controls on the top level.

It would be simplest to wrap an ASP.NET control in an additional Ext.NET container.

<ext:Container runat="server">
<Content>
<asp:Label runat="server" Text="Hello!" />
</Content>
</ext:Container>

Also I would recommend you to use Mode="Component" for a Loader.

Example

Page

<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>

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

<!DOCTYPE html>
<html>
<head runat="server">
<title>Ext.Net.MVC v2 Example</title>
</head>
<body>
<ext:ResourceManager runat="server" />

<ext:Panel ID="Panel1" runat="server" Width="200" Height="200">
<Loader runat="server" Mode="Component" Url="/Aspx/Partial" />
</ext:Panel>
</body>
</html>


Partial View

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

<ext:Container runat="server">
<Content>
<asp:Label runat="server" Text="Hello!" />
</Content>
</ext:Container>

Controller Action

public ActionResult Partial()
{
return Json(ComponentLoader.ToConfig("~/Views/Aspx/Partial.ascx"), JsonRequestBehavior.AllowGet);
}

ontiv
Jun 19, 2013, 7:39 AM
Hi Daniil,

thanks for your help.