[OPEN] [#271] How to handle IDMode in PartialViews?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1

    [OPEN] [#271] How to handle IDMode in PartialViews?

    Hi,

    We are using partial views and we are setting ID's on the page controls. We are facing the infamous multiple ID issue. I'm submitting an code example on our scenario. We use IDMode.Parent in the resource manager; When we render the partial view the button disappears from the main view and the partial view button is rendered.

    Main View: Index.cshtml
    @{
        ViewBag.Title = "Index";
    }
    <h2>Main View</h2>
    @using Ext.Net;
    @using Ext.Net.MVC;
    
    @Html.X().ResourceManager().IDMode(IDMode.Parent)
    @Html.X().Button().ID("btnPartial").Text("btnPartial")
    @Html.X().Panel().ID("tPanel").Layout(LayoutType.Fit).Region(Region.Center).Items().Loader(Html.X().ComponentLoader().Url("Test/PartialView1")
                .Mode(LoadMode.Script)
                .LoadMask(lm => lm.ShowMask = true)
                .Params(para =>
                    {
                        para.Add(new { containerId = "tPanel" });
                    }
    
                ))
    Partial View: PartialView1.cshtml
    @using Ext.Net;
    @using Ext.Net.MVC;
    
    @(Html.X().Panel().ID("pnlSub").Height(400).Width(400).Layout(LayoutType.Form).Items(Html.X().Button().ID("btnPartial").Text("btnPartial")))
    Controller
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    
    namespace Controllers
    {
        public class TestController : Controller
        {
            //
            // GET: /Test/
            public ActionResult Index()
            {
                return View();
            }
            
            public ActionResult PartialView1(string containerId)
            {
                Ext.Net.MVC.PartialViewResult pView = new Ext.Net.MVC.PartialViewResult(containerId, Ext.Net.RenderMode.AddTo);
    
                pView.WrapByScriptTag = false;
                return pView;
            }
    
        }
    }
    We need more information on how to use the IDMode property correctly. Please advise.
    Thanks
    Last edited by Daniil; Jun 10, 2013 at 3:19 PM. Reason: [OPEN] [#271]
  2. #2
    Hi @Istofix,

    IDMode is a WebForm feature. It doesn't make sense with the Razor View Engine.

    You can use a component's ItemID property and the ComponentQuerty mechanism to get access to components.
    http://docs.sencha.com/extjs/4.2.1/#...ent-cfg-itemId
    http://docs.sencha.com/extjs/4.2.1/#...ComponentQuery
  3. #3
    Thanks Daniil for the links but ItemID won't solve the issue. I'm wondering if there is a way that allow to select the component without depending on its parent. We want to be able to select a certain button of textField by using its ID only.

    In Webforms that was easily implemented using#{ControlID} Ext.NET was using the Client-ID property that is uniquely identify the control since its consists of parentId_ControlId. Now with MVC how we will handle this. We are using a component that can exist in a main view and partial view and we can't use a unique name each time we use that component? Please
  4. #4
    Just do not use ID at all if you cannot be sure that it is unique.
    Like said Daniil, you cam use ItemID and ComponentQuery to search controls inside particular containers (i am not sure why do you say that it won't solve the issue)

    Also you can use MessageBus to achieve required functionality

    Why ID is required in your case?
  5. #5
    We don't use IDs unless we need to. In our case we have a component -Records Audit Information- that consists of: a button that shows a window with couple of panels and some text fields on it when the user clicks on the button.

    This component is used in the main view and in the partial view. If we shouldn't use an ID how shall we tell what window to show? The item ID & ComponentQuery won't help since it will return an array that contains the component panel since they have the same ItemID.
    Last edited by Istofix; Jun 01, 2013 at 2:08 PM.
  6. #6
    Could you, please, provide a test case which would demonstrate your entire scenario? Please simplify as much as possible.

Similar Threads

  1. MVC Razor PartialViews with DesktopModuleProxy
    By markusn in forum 2.x Help
    Replies: 1
    Last Post: Nov 04, 2012, 3:27 PM
  2. IDMode in a UserControl
    By David Pelaez in forum 1.x Help
    Replies: 1
    Last Post: Mar 23, 2011, 8:55 PM
  3. Load PartialViews on Panel
    By Dominik in forum 1.x Help
    Replies: 5
    Last Post: Feb 25, 2011, 9:19 AM
  4. [CLOSED] [1.0] MVC PartialViews and Icons
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 7
    Last Post: Feb 19, 2010, 3:35 PM
  5. [CLOSED] [1.0] MVC PartialViews and styles?
    By Timothy in forum 1.x Legacy Premium Help
    Replies: 14
    Last Post: Feb 14, 2010, 4:12 PM

Tags for this Thread

Posting Permissions