gavio
Aug 8th, 2011, 01:27 PM
Hello.
I'm using VS2010, MVC 3, Razor and Entity Framework 4.
I want to have a drop down list with list of all countries from the Countries table. And in my model, I have just a single country id (Guid).
So, in my Model, I have:public Guid? CountryID
{ get; set; }In my Controller, I have:ViewBag.Countries = from e in new MyEntities().Countries select e;And in my View, I have:@Html.DropDownListFor(m => m.CountryID, new SelectList(ViewBag.Countries, "CountryID", "Name"), "")If I choose something or not, i get the "Value cannot be null", on the View line of the code (@Html.DropDown...). What am I doing wrong?
Also, cause I'm totally new to MVC and Entity Framework, is there a better way to achieve this? I'm Googling this for few hours now with no results...
EDIT: I have just seen I've posted in the wrong forum section, so please, redirect this. Sorry.
I'm using VS2010, MVC 3, Razor and Entity Framework 4.
I want to have a drop down list with list of all countries from the Countries table. And in my model, I have just a single country id (Guid).
So, in my Model, I have:public Guid? CountryID
{ get; set; }In my Controller, I have:ViewBag.Countries = from e in new MyEntities().Countries select e;And in my View, I have:@Html.DropDownListFor(m => m.CountryID, new SelectList(ViewBag.Countries, "CountryID", "Name"), "")If I choose something or not, i get the "Value cannot be null", on the View line of the code (@Html.DropDown...). What am I doing wrong?
Also, cause I'm totally new to MVC and Entity Framework, is there a better way to achieve this? I'm Googling this for few hours now with no results...
EDIT: I have just seen I've posted in the wrong forum section, so please, redirect this. Sorry.