Asp.net mvc2 dropdownlistfor?

A DropDownListFor helper takes a SelectList as second argument and a lambda expression to a simple property as first: %= Html. DropDownListFor( x => x. SomeProperty, new SelectList(Model.

SomeList, "ValueProperty", "TextProperty") ) % If you want to use the weakly typed DropDownList helper you could manually specify the name of the property it will be bound to but the second argument should still be a SelectList : %= Html. DropDownList( "SomeProperty", new SelectList(Model. SomeList, "ValueProperty", "TextProperty") ) %.

A DropDownListFor helper takes a SelectList as second argument and a lambda expression to a simple property as first: x. SomeProperty, new SelectList(Model. SomeList, "ValueProperty", "TextProperty") ) %> If you want to use the weakly typed DropDownList helper you could manually specify the name of the property it will be bound to but the second argument should still be a SelectList.

Darin: I don't have x => x. SomeProperty instead it shows x. List functions /collection functions because my model is a collection – DotnetSparrow May 31 at 19:55 @DotnetSparrow, well you should then modify the view model type for this partial if you want to use the strongly typed DropDownListFor helper which is what I would recommend.So you would introduce another view model which will have two properties: a scalar property to bind to and a collection property containing the values of the dropdown list which will be an enumerable.

Then you will strongly type your view to this new view model. – Darin Dimitrov May 31 at 19:57 @Darin: I used this: and I am getting DataBinding: 'EnviroTracker.Entities. Whiteout' does not contain a property with the name 'Temperature '.

– DotnetSparrow May 31 at 20:05 @Darin: I cant make viewmodel because I am calling partial view like this: Html. RenderPartial("WhiteoutList",Model. Whiteouts); and not from controller.

– DotnetSparrow May 31 at 20:07 @DotnetSparrow, well, the error message seems pretty self explanatory. As far as the view model is concerned of course that you can make one. You just need to modify the Whiteouts property of your main view model.

It should no longer be a collection but it should be the new view model I suggested you. – Darin Dimitrov May 31 at 20:07.

You'll see this behavior because DropDownListFor will peek in ModelState to see the last value for SelectedFlavorId, and build the drop down list with the last selected flavor marked as selected. It's the same magic Web Form programmers see with ViewState. Hope that helps!

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions