[CLOSED] Ambiguous call between ComboBoxBase.Builder methods (string) and (params string[]) in a PartialView

Page 1 of 2 12 LastLast
  1. #1

    [CLOSED] Ambiguous call between ComboBoxBase.Builder methods (string) and (params string[]) in a PartialView

    I don't know if I am just being block headed or if I have another version of a bug similar to this:
    http://forums.ext.net/showthread.php...(Razor-syntax)

    When I run the same code in a view that is not a partialview I get no errors, but when it is partial I get the following error:

    The call is ambiguous between the following methods or properties: 'Ext.Net.ComboBoxBase.Builder<Ext.Net.ComboBox,Ext .Net.ComboBox.Builder>.Items(string)' and 'Ext.Net.ComboBoxBase.Builder<Ext.Net.ComboBox,Ext .Net.ComboBox.Builder>.Items(params string[])'


    This is my code
    Controler:
            public ActionResult CreatePartial()
            {
                ViewBag.AdvisorListItems = (from advisor in db.Advisors select advisor).AsEnumerable().Select(x => new ListItem(x.AdvisorName, x.AdvisorId));
                return new Ext.Net.MVC.PartialViewResult { ViewName = "_CreateClient" };
            }
    PartialView:
    @model MvcApplication6.Models.Client    
    @(Html.X().Window()
            .Width(370)
            .Height(400)
            .Title("Create Client")
            .Items(
                Html.X().FormPanel()
                .Layout(LayoutType.Form)
                .BodyPadding(10)
                .Frame(true)
                .Items(
                    Html.X().TextFieldFor(m => m.Name),
                    Html.X().DateFieldFor(m => m.IAASigned),
                    Html.X().TextFieldFor(m => m.ClientCategory),
                    Html.X().CheckboxFor(m => m.IsActive),
                    Html.X().TextFieldFor(m => m.State),
                    Html.X().ComboBoxFor(m => m.AdvisorId).Items(ViewBag.AdvisorListItems),
                    Html.X().Button().Text("Submit").DirectEvents(de => de.Click.Url = Url.Action("Create"))
                )
            )
        )
    Last edited by Daniil; Sep 12, 2013 at 6:02 AM. Reason: [CLOSED]
  2. #2
    Hi @JakeM,

    Please try the following.
    @Html.X().ComboBoxFor(m => m.AdvisorId).Items(ViewBag.AdvisorListItems as IEnumerable<ListItem>)
  3. #3
    Thanks for the response @Daniil. I made the change you suggested and it is now throwing an "ArgumentNullException was unhandled by user code". Any further help would be greatly appreciated.
  4. #4
    The following works.

    View
    <!DOCTYPE html>
    <html>
    <head>
        <title>Ext.Net.MVC v2 Example</title>    
    </head>
    <body>
        @Html.X().ResourceManager()
     
       @Html.X().ComboBox().Items(ViewBag.ListItems)
    </body>
    </html>
    Controller
    public ActionResult Index()
    {
        this.ViewBag.ListItems = new List<ListItem>()
        {
            new ListItem("Item 1", "1"),
            new ListItem("Item 2", "2")
        };
        return View();
    }
    So, please try to cast to List<ListItem> in the controller.
  5. #5
    Thanks, I'll give this a try.
  6. #6
    Ok, I have made the following changes and I am still getting the same error. Again, if I run the same code, but use a full view instead of partial view it works... only in partialview am I having any problems.

    Controller:
    public ActionResult CreatePartial()
            {
                List<ListItem> AdvisorListList = new List<ListItem>();
                foreach (Advisor advisor in db.Advisors)
                {
                    AdvisorListList.Add(new ListItem(advisor.AdvisorName));
                }
                ViewBag.AdvisorListList = AdvisorListList;
                
                return new Ext.Net.MVC.PartialViewResult { ViewName = "_CreateClient" };
            }
    View:
    @model MvcApplication6.Models.Client    
    
    @(Html.X().Window()
            .Width(390)
            .Height(400)
            .Title("Create Client")
            .Items(
                Html.X().FormPanel()
                .Layout(LayoutType.Form)
                .FieldDefaults(d => {
                d.LabelWidth = 80;
                d.InputWidth = 200;
                })
                .Frame(true)
                .Items(
                    Html.X().TextFieldFor(m => m.Name),
                    Html.X().DateFieldFor(m => m.IAASigned),
                    Html.X().TextFieldFor(m => m.ClientCategory),
                    Html.X().CheckboxFor(m => m.IsActive),
                    Html.X().TextFieldFor(m => m.State),
                    Html.X().ComboBoxFor(m => m.AdvisorId).Items(ViewBag.AdvisorListList),
                    Html.X().Button().Text("Submit").DirectEvents(de => de.Click.Url = Url.Action("Create"))
                    
                )
            )
        )
    Any help would be greatly appreciated.
  7. #7
    Please clarify how do you render a partial view?

    Could you provide a full, runnable test case, please?
  8. #8
    Just to summarize the issue. The combobox is giving an error, but only in the partial view. When I use a button or an action link to get to a full view with the combobox in it, no error is thrown.

    Getting you an accurate test case for what I am doing would require a sql database. I will try giving a very simple version. I am using MVC3 with database first and Razor.

    Assume a database with one table "Advisor" with two columns

    int"AdvisorId"
    string"AdvisorName"
    populated with
    (AdvisorId: 1 AdvisorName: "Joe")
    (AdvisorId: 2 AdvisorName: "Jane")
    (AdvisorId: 3 AdvisorName: "Bob")

    A second table "Client"
    string"Name"
    string"ClientCategory"
    Date"IAASigned"
    bool"IsActive"
    string"State"
    foreign key: int"AdvisorId"
    No population is necessary for the test case, as I am making a "create" view.

    View with button for rendering a partial window:
    @model MvcApplication6.Models.Client
    @{
        ViewBag.Title = "Details";
        Layout = "~/Views/Shared/_BaseLayout.cshtml";
        var X = Html.X();
    }
    @section script
    {
    }
    @(X.ResourceManager())
    @section mainStuff
    {
    @(X.Viewport()
            .Layout(LayoutType.Border)
            .Items(
                X.Panel()
                    .ID("North")
                    .Region(Region.North)
                    .Title("Client Details")
                    .Frame(true)
                    .Height(200)
                    .AutoScroll(true)
                    .Collapsible(true),
                X.Panel()
                    .Region(Region.Center)
                    .BodyPadding(5)
                    .AutoScroll(true)
                        .Items(X.Button()
                            .Text("Partial View")
                            .DirectEvents(b => {
                                b.Click.Url = Url.Action("CreatePartial", "Client");
                                                })
                              )
                     .Content(@Html.ActionLink("Create New Client", "Create", "Client", null, null))
    )
    Controller:
    public ActionResult CreatePartial()
            {
                List<ListItem> AdvisorListList = new List<ListItem>();
                foreach (Advisor advisor in db.Advisors)
                {
                    AdvisorListList.Add(new ListItem(advisor.AdvisorName, advisor.AdvisorId));
                }
                ViewBag.AdvisorListList = AdvisorListList;
                 
                return new Ext.Net.MVC.PartialViewResult { ViewName = "_CreateClient" };
            }
    
            public ActionResult Create()
            {
                ViewBag.AdvisorListItems = (from advisor in db.Advisors select advisor).AsEnumerable().Select(x => new ListItem(x.AdvisorName, x.AdvisorId));
                return View();
            }
            [HttpPost]
            public ActionResult Create(Client client)
            {
                if (ModelState.IsValid)
                {
                    db.Clients.Add(client);
                    db.SaveChanges();
                    return RedirectToAction("Index");
                }
    
                return View(client);
            }
    The Partial View (in the shared folder)
    @model MvcApplication6.Models.Client    
     
    @(Html.X().Window()
            .Width(390)
            .Height(400)
            .Title("Create Client")
            .Items(
                Html.X().FormPanel()
                .Layout(LayoutType.Form)
                .FieldDefaults(d => {
                d.LabelWidth = 80;
                d.InputWidth = 200;
                })
                .Frame(true)
                .Items(
                    Html.X().TextFieldFor(m => m.Name),
                    Html.X().DateFieldFor(m => m.IAASigned),
                    Html.X().TextFieldFor(m => m.ClientCategory),
                    Html.X().CheckboxFor(m => m.IsActive),
                    Html.X().TextFieldFor(m => m.State),
                    Html.X().ComboBoxFor(m => m.AdvisorId).Items(ViewBag.AdvisorListList),
                    Html.X().Button().Text("Submit").DirectEvents(de => de.Click.Url = Url.Action("Create"))
                     
                )
            )
        )
    The non Partial View in the Client Folder
    @model MvcApplication6.Models.Client
    @(Html.X().ResourceManager())
    @{
        ViewBag.Title = "Create";
        Layout = "~/Views/Shared/_BaseLayout.cshtml";
    }
    
    @section mainStuff
    {
        <h1>Create Client</h1>
    
        @(
            Html.X().FormPanel()
            .Layout(LayoutType.Form)
            .Width(350)
            .FieldDefaults(d => {
                d.LabelWidth = 150;
            })
            .BodyPadding(10)
            .Frame(true)
            .Items(
                Html.X().TextFieldFor(m => m.Name),
                Html.X().DateFieldFor(m => m.IAASigned),
                Html.X().TextFieldFor(m => m.ClientCategory),
                Html.X().CheckboxFor(m => m.IsActive),
                Html.X().TextFieldFor(m => m.State),
                Html.X().ComboBoxFor(m => m.AdvisorId).Items(ViewBag.AdvisorListItems),
                Html.X().Button().Text("Submit").DirectEvents(de => de.Click.Url = Url.Action("Create"))
    
            )
        )    
    }
    Last edited by JakeM; Sep 04, 2013 at 4:57 PM.
  9. #9
    Thank you, I reproduced the issue.

    Here I am posting a simplified example. Such kind of examples we are, ideally, expecting from forum members:) Please take it into account.

    Main View
    @{
        var X = Html.X(); 
    }
    
    <!DOCTYPE html>
    <html>
    <head>
        <title>Ext.Net.MVC v2 Example</title>  
    </head>
    <body>
        @X.ResourceManager()
    
        @X.Button().Text("Partial View").DirectClickAction("CreatePartial")
    </body>
    </html>
    Partial View
    @Html.X().ComboBox().Items(ViewBag.ComboBoxItems)
    Controller Actions
    public ActionResult Index()
    {
        return View();
    }
    
    public ActionResult CreatePartial()
    {
        List<ListItem> items = new List<ListItem>();
        items.Add(new ListItem("Item 1", "1"));
        ViewBag.ComboBoxItems = items;
    
        return new Ext.Net.MVC.PartialViewResult { ViewName = "_CreateClient" };
    }
    We are investigating.
  10. #10
    A ViewBag should be set up for a PartialViewResult.
    public ActionResult CreatePartial()
    {
        Ext.Net.MVC.PartialViewResult r = new Ext.Net.MVC.PartialViewResult() { ViewName = "_CreateClient" };
    
        List<ListItem> items = new List<ListItem>();
        items.Add(new ListItem("Item 1", "1"));
        r.ViewBag.ComboBoxItems = items;
    
        return r;
    }
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 1
    Last Post: Feb 22, 2012, 6:41 AM
  2. Replies: 8
    Last Post: Jan 04, 2012, 4:23 PM
  3. Replies: 1
    Last Post: Feb 28, 2011, 8:13 AM
  4. Replies: 4
    Last Post: Feb 01, 2011, 11:54 AM
  5. Replies: 3
    Last Post: Nov 12, 2008, 5:16 AM

Posting Permissions