selectlist

SelectList with MVC2 and custom ViewModel

I have created a custom ViewModel and one of the fields is a SelectList/DropDownlist. I wanted to use EditorForModel to display the ViewModel. All the fields work except the SelectList. I have tried a few different things and nothing has come up. I saw on one post that EditorForModel was not "smart enough" to do a DropDownList and I was ...

getting the selected value on an asp.net mvc selectlist

Hello, I'm failing at getting the selected item on a mvc dropdown list. I can't stand viewdata, and every example uses it. Here is my code, thanks in advance. //controller public ActionResult Register(Models.Person APerson) { } public class Person { public Person() { using (var mod...

SelectList -> how do I find the SelectedItem.Text ?

There are times where I would like to take the SelectedList and ask for the Text item that has been selected. So using the example: SelectList sl = new SelectList( new[]{ new SelectListItem{ Text="one", Value="1"}, new SelectListItem{ Text="two", Value="2"}, new SelectListItem{ Text="three", Value="3"} }, "Text", "Value", "2" ); ...

Rendering issue using SelectList from manually defined SelectListItems in MVC 2

I am using ASP.NET MVC 2 (.NET 3.5), and need to manually define what shall be an Options list. When I do so I get a drop down menu, with each of the manual entries reading 'System.Web.Mvc.SelectListItem'. My view model defines the list as such: public SelectList YesNoList { get { List<SelectListItem> tmpLis...

Where should selectlist logic sit in ASP.NET MVC, view, model or controller?

I feel my question is close to this one, but I want a more general discussion on where code like this should sit. http://stackoverflow.com/questions/2149855/asp-net-mvc-selectlist-refactoring-question I currently create my selectlists directly on my entity model, like so. public SelectList taskDeadlineTime { get { return ne...

How to show two strings in ASP.NetDropDownList SelectList dataTextField?

This is my DropDownList in ASP.Net: <%: Html.DropDownListFor(x => x.CompanyUserFilterId, new SelectList(Model.CompanyUsers, "Id", "FirstName", Model.CompanyUserFilterId)) %> I want to list all CompanyUsers in the DropDownList and show both their FirstName and LastName property. CompanyUsers is an IEnumerable property. The code above w...