Имам часове за компания, държава и държава. Държавата е свързана с Държавата Държавата и Държавата са външен ключ за Компанията
Изгледът на проблемната компания показва както държавата, така и държавата като отделни падащи менюта. Но очаквам, когато избера държава, съответната държава да се промени или обратното. Възможно ли е това в MVC5 EF модел.
Фирмен клас
public class Company
{
public int CompanyID { get; set; }
[Required]
[StringLength(100,MinimumLength=3)]
public string Name { get; set; }
[StringLength(200)]
public string Address { get; set; }
public int? StateID { get; set; }
public virtual State State { get; set; }
public int? CountryID { get; set;}
public virtual Country Country { get; set; }
public int CompanyTypeID { get; set; }
public virtual CompanyType CompanyType { get; set; }
}
Country Class
public class Country
{
public int CountryID { get; set; }
[Required]
[StringLength(100)]
public string Name { get; set; }
public virtual ICollection<State> States { get; set; }
public virtual ICollection<Company> Companies { get; set; }
}
Държавен клас
public class State
{
public int StateID { get; set; }
[Required]
[StringLength(100)]
public string Name { get; set; }
public int CountryID { get; set; }
public virtual Country Country { get; set; }
public virtual ICollection<Company> Companies { get; set; }
}
Направих скеле и генерирах изгледа и изгледа на компанията за справка
@using (Html.BeginForm()) {
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>Company</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Address, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Address, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Address, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.StateID, "StateID", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("StateID", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.StateID, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.CountryID, "CountryID", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("CountryID", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.CountryID, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.CompanyTypeID, "CompanyTypeID", htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownList("CompanyTypeID", null, htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.CompanyTypeID, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="Create" class="btn btn-default" />
</div>
</div>
</div> } <div> @Html.ActionLink("Back to List", "Index")
@section Скриптове { @Scripts.Render("~/bundles/jqueryval") }
Всяка помощ ще бъде оценена