PDA

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



JakeM
Aug 30, 2013, 8:24 PM
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?17432-CLOSED-Ambiguous-Call-when-creating-a-button-menu-in-a-toolbar(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"))
)
)
)

Daniil
Aug 31, 2013, 9:29 AM
Hi @JakeM,

Please try the following.

@Html.X().ComboBoxFor(m => m.AdvisorId).Items(ViewBag.AdvisorListItems as IEnumerable<ListItem>)

JakeM
Aug 31, 2013, 8:47 PM
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.

Daniil
Sep 02, 2013, 6:53 AM
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.

JakeM
Sep 02, 2013, 8:03 PM
Thanks, I'll give this a try.

JakeM
Sep 03, 2013, 8:57 PM
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.

Daniil
Sep 04, 2013, 5:48 AM
Please clarify how do you render a partial view?

Could you provide a full, runnable test case, please?

JakeM
Sep 04, 2013, 4:42 PM
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"))

)
)
}

Daniil
Sep 05, 2013, 4:35 AM
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.

Daniil
Sep 05, 2013, 4:46 AM
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;
}

JakeM
Sep 06, 2013, 4:19 PM
I think we are heading in the right direction here, but I am now getting "Error executing child request for handler 'Ext.Net.SelfRenderingPage'."

applicable code:
Controller:


public ActionResult CreatePartial()
{
List<ListItem> AdvisorListList = new List<ListItem>();
foreach (Advisor advisor in db.Advisors)
{
AdvisorListList.Add(new ListItem(advisor.AdvisorName, advisor.AdvisorId));
}

Ext.Net.MVC.PartialViewResult PartialView = new Ext.Net.MVC.PartialViewResult() { ViewName = "_CreateClient" };
PartialView.ViewBag.ComboTest = AdvisorListList;
return PartialView;
}

Partial 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).InputWidth(40),
Html.X().CheckboxFor(m => m.IsActive),
Html.X().TextFieldFor(m => m.State).InputWidth(40),
Html.X().ComboBoxFor(m => m.AdvisorId).Items(this.ViewBag.ComboTest),
Html.X().Button().Text("Submit").DirectEvents(de => de.Click.Url = Url.Action("Create"))
)
)
)

Daniil
Sep 09, 2013, 5:00 AM
I cannot reproduce it with the SVN trunk and v2.2 release.

Please provide a test case which we could copy, paste and run without any change. Please simplify the code as much as you can using the following technique:
How to prepare a sample (http://forums.ext.net/showthread.php?13672&p=56687&viewfull=1#post56687)

JakeM
Sep 10, 2013, 10:27 PM
I was doing a lot of work to get a usable test for you. Then I went back to the sample that you have for binding models: http://mvc.ext.net/#/Models/Model_Bind/

Simply adding a submit button in that sample when it is bound to a model creates a blank rather than a drop down. Then I saw this:
http://forums.ext.net/showthread.php?24071-Html-X()-ComboBoxFor-bug

Evidently this is a known and intentional behaviour. This behaviour seems odd to me to say the least. The fact that the code for ComboBoxFor works for a full view, but not a partial view is baffling to me. We seem to be dropping a lot of the convenience of the whole CRUD system by making it useless for only one data input field.

I am able to get ComboBox to work, just not ComboBoxFor in a partial view.

Daniil
Sep 11, 2013, 5:33 AM
I am getting a bit confused.


I was doing a lot of work to get a usable test for you. Then I went back to the sample that you have for binding models: http://mvc.ext.net/#/Models/Model_Bind/

Simply adding a submit button in that sample when it is bound to a model creates a blank rather than a drop down.

Could you, please, demonstrate what exactly I should add to that example to reproduce "a model creates a blank"?

Also as far as I can see there are no partial views in that example.

I think a ComboBoxFor can be used in a partial view with success.

View

@{
var X = Html.X();
}

<!DOCTYPE html>
<html>
<head>
<title>Ext.Net.MVC v2 Example</title>
</head>
<body>
@X.ResourceManager()

@X.Button().Text("Render partial view").DirectClickAction("RenderPartialView")
</body>
</html>


Partial View

@model Work2MVC.Controllers.TestModel

@(Html.X().Window()
.Width(300)
.Height(300)
.Items(
Html.X().FormPanel()
.Items(
Html.X().ComboBoxFor(m => m.ComboBoxValue).Items(this.ViewBag.ComboBoxItems)
)
)
)

Controller and Model

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using Ext.Net;
using Ext.Net.MVC;

namespace Work2MVC.Controllers
{
public class TestModel
{
[Field(FieldLabel = "ComboBox")]
public string ComboBoxValue
{
get;
set;
}
}

[DirectController]
public class RazorController : Controller
{
public ActionResult Index()
{
return View();
}

public ActionResult RenderPartialView()
{
Ext.Net.MVC.PartialViewResult r = new Ext.Net.MVC.PartialViewResult()
{
ViewName = "Partial",
Model = new TestModel()
{
ComboBoxValue = "1"
}
};

List<ListItem> items = new List<ListItem>();
items.Add(new ListItem("Item 1", "1"));
items.Add(new ListItem("Item 2", "2"));
r.ViewBag.ComboBoxItems = items;

return r;
}
}
}

JakeM
Sep 11, 2013, 3:59 PM
I have to confess to being absolutely baffled. I have changed nothing in the code from last night. I have only restarted Microsoft Visual Studio, but it is working now with no issues. I have worked at reproducing the error that has been plaguing me for over a week and I can not. I thank you very much for your help and patience. It seems that Microsoft was to blame somehow.

Daniil
Sep 12, 2013, 6:01 AM
No problem. It is nice that we finally sorted it out.