Has anyone been able to use UpdateModel with DropDownLists? Whenever I have a DropDownList I get the following error. Is there a different approach for DropDownLists?
The model of type 'Models.SubscribeForm' was not successfully updated.
Having the same problem, only for Internet Explorer.
In my case it is a dropdown for a foreign key (nullable GUID), and its value is initiated with the value null which I assume is posted back and makes the UpdateModel method go haywire.... :-(
"There's no such thing as a silverbullet", The Werewolf anxiously answered the .Net developer.
(http://en.wikipedia.org/wiki/Silver_bullet)
I'm having this issue with the 1.0 version. If I show a edit form and don't change the selected item it works. If I change the selected item I get this error as well.
Having the same problem, only for Internet Explorer.
In my case it is a dropdown for a foreign key (nullable GUID), and its value is initiated with the value null which I assume is posted back and makes the UpdateModel method go haywire.... :-(
Is the GUID in the model nullable? GUID in .NET is a value type so it cannot accept NULL.
Not sure about skaue but the value in my linqtosql model is "SmallInt NOT NULL". After the post to the controller I checked the value of the column in the product model that should contain the value (ID) of the dropdown and I checked that to the database
and it is showing the right ID that should get stored. Below is the dropdown, the controller action and the html from the page. Line 20 is where the error happens. Like I said if I don't change the selected item I don't get an error.
<%
= Html.DropDownList("colQuarryID",
new SelectList((List<Quarry.QuarryDropdown>)ViewData["quarries"],
"colID", "colDisplay", Model.colProductID))%>
= Html.DropDownList("colQuarryID",
new SelectList((List<Quarry.QuarryDropdown>)ViewData["quarries"],
"colID", "colDisplay", Model.colProductID))%>
The field in the Product class is called colProductID, but the HTML field name is colQuarryID, so the model binder won't be able to make the connection between the two. Try naming the HTML field colProductID instead.
My error... I copied that dropdown from the wrong edit page (although that is error on that page). Here is what I have for that dropdown giving the error. The field on the edit screen is marked with the ._____-validation-error css after a save is requested.
<%
= Html.DropDownList("colQuarryID",
new SelectList((List<Quarry.QuarryDropdown>)ViewData["quarries"],
"colID", "colDisplay", Model.colQuarryID))%>
EDIT: Whatever I'm doing wrong it is consistent. Every page I have with a dropdown does this.
Is anyone getting the dropdown to work with model bind... I'm just wondering if this is a bug or not? If this is working from someone are the the dropdown a forign key?
ccook
Member
6 Points
6 Posts
MVC - Html.DropDownList - SelectList - UpdateModel
Oct 05, 2008 01:49 AM|LINK
Has anyone been able to use UpdateModel with DropDownLists? Whenever I have a DropDownList I get the following error. Is there a different approach for DropDownLists?
The model of type 'Models.SubscribeForm' was not successfully updated.
Thank you,
Charles
skaue
Member
157 Points
108 Posts
Re: MVC - Html.DropDownList - SelectList - UpdateModel
Oct 21, 2008 07:58 AM|LINK
Having the same problem, only for Internet Explorer.
In my case it is a dropdown for a foreign key (nullable GUID), and its value is initiated with the value null which I assume is posted back and makes the UpdateModel method go haywire.... :-(
(http://en.wikipedia.org/wiki/Silver_bullet)
CarlUman
Member
57 Points
32 Posts
Re: MVC - Html.DropDownList - SelectList - UpdateModel
Apr 20, 2009 03:00 PM|LINK
I'm having this issue with the 1.0 version. If I show a edit form and don't change the selected item it works. If I change the selected item I get this error as well.
bradwils
Contributor
5779 Points
691 Posts
Microsoft
Re: MVC - Html.DropDownList - SelectList - UpdateModel
Apr 20, 2009 03:06 PM|LINK
Is the GUID in the model nullable? GUID in .NET is a value type so it cannot accept NULL.
CarlUman
Member
57 Points
32 Posts
Re: MVC - Html.DropDownList - SelectList - UpdateModel
Apr 20, 2009 03:27 PM|LINK
Not sure about skaue but the value in my linqtosql model is "SmallInt NOT NULL". After the post to the controller I checked the value of the column in the product model that should contain the value (ID) of the dropdown and I checked that to the database and it is showing the right ID that should get stored. Below is the dropdown, the controller action and the html from the page. Line 20 is where the error happens. Like I said if I don't change the selected item I don't get an error.
<%
= Html.DropDownList("colQuarryID", new SelectList((List<Quarry.QuarryDropdown>)ViewData["quarries"], "colID", "colDisplay", Model.colProductID))%>// POST: /Product/Save [AcceptVerbs(HttpVerbs.Post)] public ActionResult Save(Product product) { product.AddModelErrors(ModelState, product.GetRuleViolations()); if (!ModelState.IsValid) { Load(); return product.colID == 0 ? View("Add", product) : View("Edit", product); } try { if (product.colID == 0) product.Add(product); else { product = product.Get(product.colID); UpdateModel(product); } product.Save(); } catch (Exception err) { ModelState.AddModelError("miscError1", "Unhandled error"); ModelState.AddModelError("miscError2", err.InnerException == null ? err.Message : err.InnerException.Message); Load(); return product.colID == 0 ? View("Add", product) : View("Edit", product); } return RedirectToAction("List"); }bradwils
Contributor
5779 Points
691 Posts
Microsoft
Re: MVC - Html.DropDownList - SelectList - UpdateModel
Apr 20, 2009 03:47 PM|LINK
The field in the Product class is called colProductID, but the HTML field name is colQuarryID, so the model binder won't be able to make the connection between the two. Try naming the HTML field colProductID instead.
CarlUman
Member
57 Points
32 Posts
Re: MVC - Html.DropDownList - SelectList - UpdateModel
Apr 20, 2009 03:56 PM|LINK
My error... I copied that dropdown from the wrong edit page (although that is error on that page). Here is what I have for that dropdown giving the error. The field on the edit screen is marked with the ._____-validation-error css after a save is requested.
<%
= Html.DropDownList("colQuarryID", new SelectList((List<Quarry.QuarryDropdown>)ViewData["quarries"], "colID", "colDisplay", Model.colQuarryID))%>EDIT: Whatever I'm doing wrong it is consistent. Every page I have with a dropdown does this.
CarlUman
Member
57 Points
32 Posts
Re: MVC - Html.DropDownList - SelectList - UpdateModel
Apr 23, 2009 06:39 PM|LINK
Is anyone getting the dropdown to work with model bind... I'm just wondering if this is a bug or not? If this is working from someone are the the dropdown a forign key?
Thanks
ypso
Member
2 Points
1 Post
Re: MVC - Html.DropDownList - SelectList - UpdateModel
Apr 29, 2009 06:47 AM|LINK
<%= Html.DropDownList("state", (SelectList)ViewData["state_list"], "stare", Model.company.state)%>
works
altafkhatri@...
Member
16 Points
10 Posts
Re: MVC - Html.DropDownList - SelectList - UpdateModel
Jul 22, 2009 12:11 AM|LINK
Check out the post at the following blog:
http://altafkhatri.com/Technical/How_to_bind_IList_with_MVC_Dropdownlist_box
MVC dropdownlist categories