[MVC] How to use a partial view in a window?

  1. #1

    [MVC] How to use a partial view in a window?

    I have a partial view that is a FormPanel, which I want to display in a window.

    Views/Shared/_MyForm.cshtml:
    <body>
    @(Html.X().FormPanel()
        .ID("MyPanel")
        .Items(items => {
            items.Add(Html.X().FieldContainer()
                ...
            );
        })
    )
    </body>
    Now I'm not sure how to get this in the window. Here is what I'm trying:
    Views/Home/Index.cshtml:
    ...items.Add(Html.X().Window()
        .ID("MyWindow")
        .Items(item => {
            item.Add(Html.X().Panel()
                .ID("MyPanel")
                .Loader(new ComponentLoader{
                    AutoLoad = true,
                    Url = "~/Home/FormPartialView"
                })
            );
        })
    )
    Controllers/HomeController.cs:
    public ActionResult FormPartialView(string containerId)
    {
        Ext.Net.MVC.PartialViewResult pr = new Ext.Net.MVC.PartialViewResult(containerId, Ext.Net.RenderMode.AddTo);
        pr.SingleControl = true;
        return pr;
    }
    First of all, I don't know if this is right at all... Secondly, how do I pass "containerId" to the controller?
  2. #2
    If want just put your PartialView inside window you can just ItemsFromPage:

    Index.cshtml

    @Html.X().Window().ItemsFromPage(this, "~/Views/Test/WindowShow.cshtml").Title("Window").Layout("Fit").Height(200).Width(300)
    Controller:

    public ActionResult Index() {
    	return View();
    }
    
    public Ext.Net.MVC.PartialViewResult WindowShow()
    {
    	return new Ext.Net.MVC.PartialViewResult {
    		ViewName = "WindowShow"
    	};
    }
    WindowShow.cshtml

    @(Html.X().FormPanel()
        .Items(i =>
               	{
               		i.Add(Html.X().TextField().FieldLabel("Text Field 1"));
                    i.Add(Html.X().TextField().FieldLabel("Text Field 2"));
    			}
        )
    )
    Also, it will be useful for you check this thread http://forums.ext.net/showthread.php...xt-PartialView
    Last edited by Baidaly; Nov 15, 2012 at 2:51 AM.
  3. #3
    Thanks, it works for the window!

    However, I want to use the partial view in a couple places on my page - i.e., I have an "edit user" panel, and an "add user" popup, and I want both to use the same form. Rather than repeating the code twice, I thought a partial view would do the trick... But using

    .ItemsFromPage(this, "~/Views/Shared/MyForm.cshtml")
    in Index.cshtml twice gives me a server error: "An item with the same key has already been added."
    Last edited by KBorkiewicz; Nov 15, 2012 at 4:24 PM.
  4. #4
    I don't see any problems and exceptions. I have tried following code in Index.cshtml:

    @Html.X().Window().ItemsFromPage(this, "~/Views/Test/WindowShow.cshtml").Title("Window 1").Layout("Fit").Height(200).Width(300).X(1)
    
    @Html.X().Window().ItemsFromPage(this, "~/Views/Test/WindowShow.cshtml").Title("Window 2").Layout("Fit").Height(200).Width(300).X(300)
    Can you post example of your problem?
  5. #5
    The problem was that the partial view had .ID fields set. I took the IDs out and it works.
  6. #6
    I'm searching a way to use Partial View twice, without removing IDs which are usefull for some features.
    The Desktop Module way should be the right way, but I can't put single desktop modules in partial view.

    Anyone has an idea?

    Thanks.
  7. #7
    Can you post the example?
    Last edited by Baidaly; Nov 22, 2012 at 12:24 AM.
  8. #8
    The example is the same as the window sample in mvc.ext.net, but i do not want to render on click a window, but a desktop module.
    I would define a desktop component in a page index.cshtml, without any hard coded desktop module in it. Then i want to write a desktop module in a partial cshtml file, and render it (also twice or more), via a button and a controller action, attaching it to the desktop control in index.cshtml.

    This should let me use IDs in desktop modules (I'ce already tryied it) without any exception.


    Thank you for any idea.

Similar Threads

  1. [CLOSED] [2.1] MVC Partial View
    By softmachine2011 in forum 2.x Premium Help
    Replies: 4
    Last Post: Aug 23, 2012, 1:04 PM
  2. [CLOSED] Partial View Error
    By peter.campbell in forum 1.x Premium Help
    Replies: 1
    Last Post: Feb 10, 2012, 11:32 AM
  3. Javascript not work in partial view mvc.ext.net
    By theblackcat_2902 in forum 1.x Help
    Replies: 9
    Last Post: Aug 24, 2011, 11:31 AM
  4. [CLOSED] Modal Partial view Window
    By SymSure in forum 1.x Premium Help
    Replies: 6
    Last Post: May 19, 2011, 6:26 PM
  5. [CLOSED] MVC- How to display a Partial View from a window
    By SymSure in forum 1.x Premium Help
    Replies: 5
    Last Post: Apr 08, 2011, 12:32 PM

Tags for this Thread

Posting Permissions