Kam klasa Kompani, Vendi dhe Shteti. Shteti është i lidhur me Shtetin e Shtetit dhe Vendi janë çelësi i huaj për Kompaninë
Problemi "Pamja e kompanisë" tregon si gjendjen ashtu edhe shtetin si pika të veçanta me rënie. Por pres që kur të zgjedh shtetin, shteti përkatës duhet të ndryshojë ose anasjelltas. A është e mundur kjo në modelin MVC5 EF.
Klasa e Kompanisë
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; }
}
Klasa e vendit
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; }
}
Klasa shtetërore
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; }
}
Unë kam bërë skela dhe gjenerova pamjen dhe pamjen e kompanisë për referencë
@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 { @Scripts.Render("~/bundles/jqueryval") }
Çdo ndihmë do të vlerësohej