Dropdownlistfor MVC ASP.Net VB -


I send data to my dropdown list and I can select that data, but when I post it on the method Clicking on the button I get an error:

An exception to the type of "SystemInvalidOperationException" type was in System.Web.Mvc.dll but the user was not in the code

< P> Additional information: ViewData item key 'Selected item' type is of 'System.String', but should be 'IEnumerable' type. "

My model code:

My model code:

  Public  

I thought that the first value in the razor view is in the drop down list. Class Nupreses Index Public Property Name String Public Property As String Public Property As String Public Property Item As String Public Property Item IEnumerable (SelectListItem) End Class

My determination Senior C Ode:

  & lt; HTTPGet & gt; Function AddNewProces () ActionResult Dim listBoxData = New NewProcessIndex {{. {= .Value = 1, with Value = {New SelectListItem ()). Text = "item 1"}, {.Value = 2, with new SelectListItem (). = "Item 2"}, {Select.ListItem} {return. Text = "item 3"}}} Return (listBoxData) termination function & lt; HttpPost & gt; ActionResult newProcesData.DataSource1 = newProcesData.SelectedItem Return View (newProcesData) termination function  

as the addNewProces (NewProcesData as NewProcessIndex) and finally my view code:

  @ Model Type Newprosse Index & lt; H2 & gt; AddNewProces & lt; / H2 & gt; @Usage (Html.BeginForm ("AddNewProces", "Admin", FormMethod.Post)) @ & div; Div class = "form-horizontal" & gt; @html LabelFor (Function (M) M. Nom) @html TextboxFor (Function (M) M. Nom) @html Validation Message for (Function (M) M.NM) @HTMLFraudown ListFor (Function (X) X Selected Etym, Model.Entems) & lt; Input type = "submit" value = "update process" /> & Lt; / Div & gt; Use the end @If form.mast.phost then @ & lt; P & gt; @model Name & lt; / P & gt; @ & Lt; P & gt; @ Model.DataSource2 & lt; / P & gt; Edit if:  

Edit: Strange thing ... The dropdown does not work for the list, but the list box to work in this form:

 < Code> @HTML_listbox (function x) x Selected items, models. ITEMS) Perhaps the fact that I am returning a model for the issue is an issue. Was or was joking with me  
  @ if if post then ... end if  

I'm not sure what caused the error, but Now I'm using ListBoxFor and everything should work like it .... Strange :) If no one still explain to me why it does not work as expected (well I did it workThe Mmid is) like it :) I answer right away


Comments

Popular posts from this blog

sqlite3 - UPDATE a table from the SELECT of another one -

c# - Showing a SelectedItem's Property -

javascript - Render HTML after each iteration in loop -