ASP.NET MVC DropDownList Validation


ASP.NET MVC DropDownList Validation



I have

[DisplayName("Country")] public List<SelectListItem> Countries { get; set; } 

property in strong-type Model View class for DropDownList.

When I try to check if the ModelState.IsValid on form postback it's always false & error for Countries tells "Can't convert [value] to SelectListItem" or some of a kind.

I figured out there is no straight-forward mapping for drop down selected value (looks like I'll have to read value from Form value collection), but how can I ignore binding and validation for List property? I just want to make ModelState.IsValid attribute to be true if all the other fields are populated properly.

Thank you in advance




Multible jquery .load() methods not running concurrently in MVC 2

1:



How 404 error asp.net mvc 2 IIS 7?
Finally I used workaround..
ASP.NET MVC Error: Page is not allowed here because it does not extend class 'System.Web.Page'
My model now:.
Extension method not working if I set controller property in Action, works in OnExecuting
class Model { ... 


Using external javascript files with asp.net MVC
[DisplayName("Country")] List<Country> Countries; Guid CountrySelected <-- new field! ...


how to give image path in java script in asp.net mvc
}
I use Html.DropDownList("CountrySelected", Model.Countries.Select(x => new SelectItemList..


User.Identity.Name returning NT AUTHORITY\NETWORK SERVICE i want Domain\USER
).
ASP.NET MVC download image rather than display in browser
instead of HtmlDropDownListFor.

HtmlDropDownListFor maps [id selected] to List not to CountrySelected property.

Now [id selected] is mapped to CountrySelected .


2:


Is it because the value submitted is of type String or Country rather than a list of SelectListItem or List<SelectListItem>.. What are you binding to the control in the UI?. try .
[DisplayName("Country")] public List<Country> Countries { get; set; } 
Where Country is the type name from your DAL.. EDIT: Based on the error you are recieving, it sounds like the model is expecting the value to be a String so try swapping List<Country> for List<String>..
[DisplayName("Country")] public List<string> Countries { get; set; } 



53 out of 100 based on 48 user ratings 373 reviews

@