html.dropdownlistfor

what is the best way to use Html.DropDownListFor when you have a list of objects ?

In my view model if have a: List<Car> where car has an Id and a name. I want to create a dropdown box using Html.DropDownListFor() what is the best way to hook this up as i want to have the value of the item be the Id and the display to be the Name of the Car. ...

Incremental Sequencing DropDownListFor Binding?

I am using incremental sequencing for a collection of objects in a form. All works fine and dandy except when I need to use DropDownListFor. Lots of questions concerning binding a dropdown and selecting the correct value, which is working fine in my case. However I am unclear on what is supposed to have on the HttpPost action in my contr...

ASP.Net MVC 2 DropDownListFor in EditorTemplate

I have a view model that looks like this: namespace AutoForm.Models { public class ProductViewModel { [UIHint("DropDownList")] public String Category { get; set; } [ScaffoldColumn(false)] public IEnumerable<SelectListItem> CategoryList { get; set; } ... } } It has Category and Cate...

How to retrieve value from DropDownListFor html helper in ASP.NET MVC2?

Hello I know there was few similar questions here about DropDownListFor, but neither helped me... I use Entity Framework as ORM in my project. There's EF model called "Stete". Stete has Foreign on EF model called "Drustva" Now I'm trying to make a form for editing the data, for Stete model. I managed to display everything, including S...

Html.DropDownListFor not behaving as expected ASP.net MVC

Hello, I am new to ASP.net MVC and I am having trouble getting dropdown lists to work correctly. I have a strongly typed view that is attempting to use a Html.DropDownListFor as follows: <%=Html.DropDownListFor(Function(model) model.Arrdep, Model.ArrdepOptions)%> I am populating the list with a property in my model as follows: Publi...

How to write a simple Html.DropDownListFor()?

I'm new in ASP.NET MVC 2 and I'd like to write a very simple dropdown list which gives static options. For example I'd like to provide choices between "Red", "Blue", and "Green". ...

Saving Dropdown list selection with Entity Framework in ASP.NET MVC solution

Hi, I'm looking for advice on a decent pattern for dropdown list selection and persistence of the selection with POCO EF please. I have a list of IEnumerable<Country> in my view model where Country is a POCO loaded via EF. There is an Address property on the view model that takes the current or user selected value on it's Country prop...

ASP.NET MVC: DropDownListFor doesn't select any option

I have this to populate a drop down list in an ASP.NET MVC view. <%= Html.DropDownListFor(model => model.Bikes, Model.Bikes.Select( x => new SelectListItem { Text = x.Name, Value = Url.Action("Details", "Bike", new { bikeId = x.ID }), Selected = x.ID == Model.ID, })) %>...

No "Specified argument was out of the range of valid values" with DropDownListFor.

In one of my views I want to output a textbox: Html.TextBoxFor(x=>x.Foo[0].Bar) %> This gives me the error "Specified argument was out of the range of valid values" if Model.Foo is empty. I have tried this with same model but with a drop down list instead: Html.DropDownListFor(x=>x.Foo[0].Bar, Model.BarList) %> No error... This i...

Why does a lamba-expression work, but when accesing the Model object directly it doesn't?

Here's the error I get: Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0411: The type arguments for method 'System.Web.Mvc.Html.SelectExtensi...

Why won't my Model accept what I'm selecting from the DropDownList?

I edit the Dinner (from the NerdDinner tutorial) and save it, but the Country isn't persisted. Here's my code: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace NerdDinner.Models { public class DinnerFormViewModel { private static string[] _countries = n...

Issue with MVC2 DropDownListFor, only displaying the class-name

Good day, I have this problem with Html.DropDownListFor which I can't seem to work out.. It gives me the correct number of options, if I do a breakpoint in the code where it is supposed to render the list, the "SelectItemList" object contains the items with correct values, but the actual HTML it spits out is the following: <select id="...

Html.DropDownList returns an empty string in IE, works fine in FF

I have a dropdownlist that is simply a list of strings (salutations). When I submit the form, the field is an empty string no matter what value is selected. In firefox, it works exactly as expected...but not in IE. <tr> <td>Salutation : </td><td><%= Html.DropDownList("Salutation", new SelectList(Salutations.SalutationList, ...

DropDownList not autosized properly within Jquery UI Accordion

My dropdownlist width is smaller than the longest text in the SelectList. When I click the dropdown, it resizes to fit properly. If I remove the .accordion from the div, the dropdowns all size correctly when the page loads. How can I get it to size properly? This is how I set the accordion. $("#acc").accordion({ ...

Asp.Net mvc 2 , DropDownListFor and Editor Template . Selected Value dosen't work

I Have 2 views. ProductForm.aspx and Category.ascx. CategoryForm is a Partial View. I Call the Category.ascx from the ProductForm with EditorFor(model => model.Category) . In this partial view, there is a DropdownlistFor with all the category. The problem is the Selected Value for a specific Product Category. The selected value dosen't w...

DropDownListFor population problem

I have the following 2 classes: public class SomeClass { public int SomeClassID { get; set; } ... } public class AnotherClass { public int AnotherClassID { get; set; } public int AnotherClassText { get; set; } } I have a ViewModel that contains the following: public class MyViewModel { public SomeClass { get; set; } publ...

Html.DisplayFor DropDownList problem

Im using asp.net mvc 2. I have a model Supermodel that consists of 2 models TestModel1 and TestModel2. In SuperModelView Im doing the following thing: <%: Html.DisplayFor(x=> x.TestModel1, "TestModel1Template") %> Its working just fine, except for the fact, that dropdownlist is populated but selected value is not set. Im using the fo...

enable html dropdown through controller in mvc

i have an scenario where i have to perform some action according to selection of the dropdown . for basic refrence you can use the example of country,state,city. i am able to populate the country list at that time i have set the other two drop downs to disable. after the countries are populated i want to select the state.it is gettin...

DropDownList Validation - Problem

Hello guys... I'm having a problem in ASP.NET MVC with DropDownList validation. I have two actions "Create". They are defined as follow: public ActionResult Create() { var categoriasDownloads = from catDown in modelo.tbCategoriasDownloads orderby catDown.TituloCategoriaDownload ascending ...