well i'm working with ASP MVC crud operations with generated forms with Entity Framework, but not all fields are the ones that i need to be shown. I mean, for example, a Create operation for the model Town (name, country).
first, country field is a reference on the table Country (i must maybe display a combobox filled with all countries on the database)
second, a many-to-many relationship w开发者_如何转开发ith Transport (car, bus, train) and Town : here a town can have many transports and a transport can be found in many touns. here is may question : Can i display here a multiple choice (a checkbox list) with all transports that exists in the database?
i really need help please, maybe some questions are a little bit similar to my request but i made a search but i found nothing that may help me. Thank You All ^^
you have to bring county and transport data into your view. what i guess from your answer is that you are sending your entity directly to your view. you should rather create a viewmodel including enumeration of countries and transports and then on your view you can use
<%:Html.DropDownListFor(x=>x.CountryID, new SelectList(Model.Countries, "CountryID", "countryName"))%>
plz look at this questions to find more about selectlist binding with viewmodels
精彩评论