selectlistitem

Binding a simple sort dropdown to a list in MVC.

Hi guys, Im trying to bind a dropdownlist in ASP.NET MVC to a class. Luckily for me this will be a number between 1 and 10, however I'm not getting the output in my HTML that I would expect. I've set both the value and text properties which are populated ok in the View, but the selected value refuses to render. This is within the initia...

SelectListItem not selected even when explicitly set to true

This question relates to ASP.NET MVC 2 RC (December drop). The basic problem is that when creating a drop down list with a default selected value, the "selected" attribute is either not rendered to HTML or attributed to the wrong option. Here's some code to demonstrate the wrong option issue: Here's a function to generate some values ...

Multiselect list not showing selected items in c# mvc using linq2sql

I've tried many different ways to pass the selected items to the multiselect list with no luck. Finally, I tried this, which I think should display all the items as selected and still nothing in the list is selected. public MultiSelectList Companies { get; private set; } Companies = MulitSelectList(subcontractRepository.SubcontractCom...

Strongly typed view with a SelectList for DropDownList via ViewData: type mismatch on submit

I am trying to create a form in ASP.NET MVC2 RC 2 that is based on a calendar event object. The object has eventTypeId which is a System.Int32 that I need to populate with via a select list. The controller to create the initial view is: [WAuthorize] public ActionResult AddCalendarEvent() { CalendarEventTypesManager calendarEventTyp...

How to code a C# Extension method to turn a Domain Model object into an Interface object?

When you have a domain object that needs to display as an interface control, like a drop down list, ifwdev suggested creating an extension method to add a .ToSelectList(). The originating object is a List of objects that have properties identical to the .Text and .Value properties of the drop down list. Basically, it's a List of Select...

Easiest way to specify the selected option to a dropdown list in ASP.NET MVC

I have a list of options (IEnumerable< SelectListItem >) in my model that I want to use in multiple dropdowns in my view. But each of these dropdowns could have a different selected option. Is there an easy way to simply specfiy which should be selected if using the Html.DropDownList helper? At this point, the only way I can see is ...

How can I convert an enumeration into a List<SelectListItem>?

i have an asp.net-mvc webpage and i want to show a dropdown list that is based off an enum. I want to show the text of each enum item and the id being the int value that the enum is associated with. Is there any elegant way of doing this conversion? ...

how do i put backcolor on a selectListItem

i have an asp.net mvc page and i want to have a dropdown list with different background color like this page i have the following code to display a dropdown list <label>Data Source: </label><% = Html.DropDownList("DataSource", Model.CalendarDataSources, new { @id = "calendarDSDropdown", @class = "calendarDSDropdown" })%> in my viewmo...