KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have an issue with my app, ill try explain by example, I have a form, this form exist of several textboxes and dropdown lists. For reusability I merged 3 drop down lists into a partial view, this partial view i load with @Html.Action, this works ok, when i start the form i see everything appears as it should be, although I dont know why but those required drop down lists directly are shown with red start and said it is required fields. But when i fill everything in, and i select the values from the drop down lists, and i click on OK, the values from drop down lists are NULL. I think it will be more comprehendable with a code example: Main model: public class FormModel { [Required] public string UserName { get; set; } [Required] [Display(Name = "Birthdate")] public DateTime? Birthdate { get; set; } //This is what i'm talking about, that is not being set, the location public Location Location { get; set; } } Here is the location class, which is then passed to the partial view and normally i think should be set, it looks like this: public class Location { [Required] [Display(Name = "Country")] public string CountryId { get; set; } [Required] [Display(Name = "Region")] public string RegionId { get; set; } [Required] [Display(Name = "City")] public string CityId { get; set; } } Now we have a partial view for the location: @model TestWebsite.Models.Location <tr> <td class="editor-label"> @Html.LabelFor(m => m.CountryId) </td> <td class="editor-field"> @Html.DropDownListFor(m => m.CountryId, Model.Countries, "---select--", null) </td> <td> @Html.ValidationMessageFor(m => m.CountryId) </td> </tr> <!-- Region --> <tr> <td class="editor-label"> @Html.LabelFor(m =&
Tags (comma-separated)
Save Edits
Cancel