खात्यासाठी ASP.NET MVC5 संस्था फ्रेमवर्क गट फील्ड (देश, राज्य)

माझ्याकडे कंपनी, देश आणि राज्य वर्ग आहेत. राज्य देशाशी संबंधित आहे आणि देश ही कंपनीची विदेशी की आहे

समस्या कंपनी दृश्य राज्य आणि देश दोन्ही वेगळे ड्रॉपडाउन म्हणून दाखवते. परंतु मी अपेक्षा करतो की मी राज्य निवडतो तेव्हा संबंधित देश बदलला पाहिजे किंवा उलट बदलला पाहिजे. 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; }

}

देश वर्ग

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")

@सेक्शन स्क्रिप्ट्स { @Scripts.Render("~/bundles/jqueryval") }

कोणत्याही मदतीचे कौतुक केले जाईल


person Gopi    schedule 16.07.2015    source स्रोत


उत्तरे (2)


आपल्याला कॅस्केडिंग ड्रॉपडाउन सूचीची आवश्यकता आहे. येथे CodeProject मधील एक उदाहरण आहे.

http://www.codeproject.com/Articles/258172/Simple-Implementation-of-MVC-Cascading-Ajax-Drop-D ची साधी-अंमलबजावणी

person LSU.Net    schedule 16.07.2015
comment
धन्यवाद, मॉडेल आणि कंट्रोलरमध्ये या दोन गुणधर्मांचे गटबद्ध करण्याची कोणतीही शक्यता आहे का, जेणेकरून व्हिज्युअल स्टुडिओ माझ्यासाठी कोड तयार करू शकेल. - person Gopi; 16.07.2015
comment
नाही. तुम्हाला कोड लिहावा लागेल. इतरांनी निदर्शनास आणल्याप्रमाणे एचटीएमएल कंट्रोल्समध्ये अवलंबनाची संकल्पना नसते - person LSU.Net; 16.07.2015

MVC5 EF मॉडेलमध्ये हे शक्य आहे का?

होय. परंतु तुम्हाला काम करावे लागेल (किंवा ते तुमच्यासाठी करणारी नियंत्रणे मिळवा (खरेदी करा).

मर्यादा MVC नाही, परंतु डीफॉल्ट एचटीएमएल नियंत्रणांमध्ये दुसऱ्यावर अवलंबून राहण्याची संकल्पना नाही. जेव्हा देश ड्रॉप डाउन बदलतो तेव्हा राज्य ड्रॉप डाउनची सामग्री बदलण्यासाठी कोड लिहा (यामध्ये निवडलेल्या देशानुसार राज्यांची यादी फिल्टर करणे समाविष्ट असू शकते) किंवा असे करणारे तृतीय पक्ष नियंत्रण मिळवा (ही एक सामान्य आवश्यकता आहे त्यामुळे बरेच तेथे नियंत्रण ठेवते1).


1 पण स्टॅक ओव्हरफ्लो टूल्सच्या शिफारशी करत नाही.

person Richard    schedule 16.07.2015
comment
मी तृतीय पक्ष नियंत्रणे वापरण्याचा विचार करत नाही. त्यामुळे व्ह्यूमध्ये मॅन्युअली करणे हा एकमेव पर्याय आहे किंवा काही उपाय आहे - person Gopi; 16.07.2015