[CLOSED] How to Create dynamic LinkButton from the controllers of the MVC model

  1. #1

    [CLOSED] How to Create dynamic LinkButton from the controllers of the MVC model

    Hi,

    I need to create a list of Link Buttons to donwload docs. A basic example (only one linkbutton):

    Page Code:
    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>DocumentacionJunta</title>
        <link href="../../Content/Style/Site.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <form id="fileform" class="x-hide-display" />
        <ext:ResourceManager ID="ResourceManagerDelelgacion" runat="server" >
            <DirectEvents>
                <DocumentReady Url="~/DocumentacionJunta/LoadLinks" />
            </DirectEvents>
        </ext:ResourceManager>
        <ext:Viewport ID="vpDocumentacionJunta" runat="server">
            <Items>            
                <ext:Panel ID="containerEnlaces" runat="server" Margins="5 5 5 5" Frame="true" />
            </Items>
        </ext:Viewport>
    </body>
    </html>
    DocumentReady Controller:
    public AjaxResult LoadLinks()
    {
                AjaxResult respuesta = new AjaxResult();
    
                Ext.Net.LinkButton link = new Ext.Net.LinkButton();
                link.Text = "Prueba de Descarga";
                link.DirectEvents.Click.Url = "/GestionDocumental/DownloadDoc/";
                link.DirectEvents.Click.FormID = "fileform";
                link.DirectEvents.Click.Buffer = 300;
                link.DirectEvents.Click.IsUpload = true;
                link.DirectEvents.Click.Method = Ext.Net.HttpMethod.GET;
                link.DirectEvents.Click.AutoDataBind = true;
                link.DirectEvents.Click.ExtraParams.Add(new Ext.Net.Parameter("idDoc", "99", Ext.Net.ParameterMode.Value));
    
                respuesta.Script = link.ToScript(Ext.Net.RenderMode.AddTo, "containerEnlaces");
                
                return respuesta;
    }
    LinkButton Contoller:

    public ActionResult DownloadDoc(int idDoc)
    {
                gestor = new GestDoc();
                Downloader doc = gestor.DownloadDocs(int.Parse(idDoc), Saving.Db);
                return doc;
    }
    The problem is that value of parameter idDoc is null in DownloadDoc contoller.

    Thanks so much!
    Last edited by Daniil; Dec 12, 2011 at 2:40 PM. Reason: [CLOSED]
  2. #2
    Hi,

    Please set up
    link.DirectEvents.Click.CleanRequest = true;
  3. #3
    Thanks, now works fine!
  4. #4
    First: Sorry to write in a closed issue.

    In the example adove, if you create more than one link will be placed in the same line.

    How I can place them on different lines?

    Thank you and sorry again.
  5. #5
    You should use a respective layout.

    I would suggest to try a FormLayout.

    Please set up Layout="FormLayout" and HideLabels="true" for the containerEnlaces.
  6. #6
    Sorry, I tried but it does not work.

    The code:

    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <%@ Register Src="../Common/ucCortesia.ascx" TagName="ucCortesia" TagPrefix="uc" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>DocumentacionJunta</title>
        <link href="../../Content/Style/Site.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
        <form id="fileform" class="x-hide-display" />
        <ext:ResourceManager ID="ResourceManagerDelelgacion" runat="server" >
            <DirectEvents>
                <DocumentReady Url="~/DocumentacionJunta/CargaDocumentacion" />
            </DirectEvents>
        </ext:ResourceManager>
        <ext:Viewport ID="vpDocumentacionJunta" runat="server" Layout="BorderLayout"  >
            <Items>            
                <ext:Panel runat="server" Region="North" Layout="FitLayout" Height="45" Margins="5 5 5 5" Frame="true">
                    <Content>
                        <uc:ucCortesia ID="ucCortesiaDocumentacionJunta" runat="server" Texto="Desde aquí tendrá acceso a la documentación de la Junta." />
                    </Content>
                </ext:Panel>
                <ext:Panel ID="containerEnlaces" runat="server" Region="Center" Margins="5 5 5 5" Padding="10" Frame="true" Layout="FormLayout" HideLabels="true">                
                </ext:Panel>
            </Items>
        </ext:Viewport>
    </body>
    </html>

    Controller:
    public AjaxResult CargaDocumentacion()
    {
                AjaxResult respuesta = new AjaxResult();
                StringBuilder script = new StringBuilder();
    
                IQueryable<TB_M_DOCUMENTACION> documentos = entidadDocumentacion.ObtenerDocumentacionJunta(entidadConvocatorias.ObtenerIdConvocatoriaVigente());
    
                Ext.Net.LinkButton link;
    
                foreach (TB_M_DOCUMENTACION doc in documentos)
                {
                    link = new Ext.Net.LinkButton();
                    link.Text = doc.DE_NOMBRE + " (" + doc.DE_DESCRIPCION + ").";
                    link.DirectEvents.Click.Url = "/GestionDocumental/DownloadDocJunta/";
                    link.DirectEvents.Click.FormID = "fileform";
                    link.DirectEvents.Click.Buffer = 300;
                    link.DirectEvents.Click.IsUpload = true;
                    link.DirectEvents.Click.Method = Ext.Net.HttpMethod.GET;
                    link.DirectEvents.Click.AutoDataBind = true;
                    link.DirectEvents.Click.CleanRequest = true;
                    link.DirectEvents.Click.ExtraParams.Add(new Ext.Net.Parameter("idDoc", doc.ID_DOCUMENTO.ToString(), Ext.Net.ParameterMode.Value));
                    script.Append(" " + link.ToScript(Ext.Net.RenderMode.AddTo, "containerEnlaces"));
                }
    
                respuesta.Script = script.ToString();
                
                return respuesta;
    }
  7. #7
    Please use VBoxLayout. It's more consistent layout in this case.

    Also I would suggest to pass a container's as a parameter of a controller action.

    Example View
    <%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>
    
    <%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Ext.Net Example</title>
    </head>
    <body>
        <ext:ResourceManager runat="server">
            <DirectEvents>
                <DocumentReady Url="/Test/GetLinkButtons">
                    <ExtraParams>
                        <ext:Parameter Name="containerId" Value="#{Panel1}" Mode="Value" />
                    </ExtraParams>
                </DocumentReady>
            </DirectEvents>
        </ext:ResourceManager>
        <ext:Viewport 
            runat="server" 
            Layout="BorderLayout">
            <Items>
                <ext:Panel 
                    ID="Panel1" 
                    runat="server" 
                    Region="Center" 
                    Layout="VBoxLayout" />
            </Items>
        </ext:Viewport>
    </body>
    </html>
    Controller
    using System;
    using System.Text;
    using System.Web.Mvc;
    using Ext.Net.MVC;
    
    namespace Mvc.Controllers
    {
        public class TestController : Controller
        {
            public AjaxResult GetLinkButtons(string containerId)
            {
                StringBuilder script = new StringBuilder();
    
                Ext.Net.LinkButton link;
    
                for (int i = 0; i < 5; i++)
                {
                    link = new Ext.Net.LinkButton()
                        {
                            Text = "Link " + i,
                            Width = 100
                        };
    
                    script.Append(link.ToScript(Ext.Net.RenderMode.AddTo, containerId));
                }
    
                return new AjaxResult(script.ToString());
            }
        }
    }
  8. #8
    Thanks, with VBoxLayout works fine!

Similar Threads

  1. [CLOSED] Create a dynamic event for dynamic components.
    By stoque in forum 1.x Legacy Premium Help
    Replies: 10
    Last Post: May 10, 2011, 9:16 PM
  2. Replies: 3
    Last Post: Jan 20, 2011, 9:17 AM
  3. [CLOSED] CheckboxSelectionModel and RowSelectionModel dynamic create
    By albayrak in forum 1.x Legacy Premium Help
    Replies: 12
    Last Post: Dec 24, 2010, 6:41 AM
  4. [CLOSED] Create dynamic grid from XML
    By Hari_CSC in forum 1.x Legacy Premium Help
    Replies: 3
    Last Post: Apr 07, 2010, 1:43 PM
  5. How to dynamic create DesktopWindow?
    By iscript in forum 1.x Help
    Replies: 2
    Last Post: Aug 07, 2009, 2:25 AM

Posting Permissions