vb.net - Html.DropDownListFor not behaving as expected ASP.net MVC -


I'm new to Aspiknet MVC and I'm having trouble working correctly dropdown lists.

I have a strongly typed view that is trying to use HTML. Dropdown List Fire: & gt;

I limited the list with a property in your model:

  list as public Reedlain property ArrdepOptions () (the SelectListItem) get dim list new list (as SelectListItem) are dim arriveListItem new SelectListItem () dim departListItem as new SelectListItem () as arriveListItem.Text = arriveListItem.Value = ArriveDepart.Arrive departListItem.Text = "departure" DepartListItem.Value = ArriveDepart "arrive at". Get Select Case Me.Arrdep case of arrival Depart.Arrive: arriveListItem.Selected = True Case Else: DepartListItem.Selected = True End Select list.Add (departListItem) Return of list.Add (arrivalListItem) List End End End Property  

Select Case works to find and it sets the right SelectListItem as selected, but when my view drops the dropdown list, whatever is marked as selected HTML It has been done, she is not nobody, she is selected.

I am clearly doing something wrong or forgetting something, but I can not know for sure what my life is.

It has been found that I had to write a dropdown list assistant, if I needed an article This is my code. This article is almost translated into VB from the example C #. _ = As public function EnumDropDownList (TEnum a) (ByVal HtmlHelper HtmlHelper, as ByVal name string, MvcHtmlString dim values ​​as ByVal selectedValue as as TEnum) IEnumerable (of TEnum) [Enum] .GetValues SelectListItemkValue (GetType (TEnum)) dim list as new list (SelectListItem of) new SelectListItem as (for each value as TEnum value dim selectListItem) selectListItem.Text = value.ToString () = Value.ToString () selectListItem.Selected = (value.Equals (selectedValue)) Add List (Select ListEmem) Next Dim Item IEnumerable (SelectListItem's) = List A Return Return html form. Dropdown list (name, item) end function & lt; Extension () & gt; _ Public Function of EnumDropDownListFor (TModel to TEnum) (ByVal HtmlHelper as HtmlHelper (TModel), as byVal Expression Expression (TModel, TEnum) of function) MvcHtmlString Dim Metadata ModelMetadata = ModelMetadata.FromLambdaExpression (Expression, HtmlHelper As in. ViewData) dim values ​​as IEnumerable (TEnum's) = [Enum] .GetValues ​​(GetType (TEnum)) List retard values ​​as new list (SelectListItem) selectListItem New SelectListItem For each value as TEnum () selectListItem.Text = value .toString () selectListItem.Value = va Lue.ToString () selectListItem.Selected = (value.Equals (metadata.model)) list.Add (selectListItem) Next dim item as IEnumerable (selectListItem) = return return htmlHelper.DropDownListFor (Expression, Item) and Function End Module and namespace


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -