0

ドロップダウンから国を選択する際に州の ddl を埋めようとしています。関数の国名基準に基づいてフィルター結果を取得できstateListます。しかし、ビューに戻ると、すべての状態リストが表示されます。どこが間違っていたのか教えていただけますか。

前もって感謝します。

//This is my controller class 
public ActionResult  Country()
{
    Country country = new Country();
    ListCountry objCountry = new ListCountry(country);
    return View(country);
}

//This method calls  on selection of countryanem   
public ActionResult stateList()
{
    Country country = new Country();
    var state = Request.Form["_countryId"];
    country.CountryId = _countryId; 
    ListCountry objCountry = new ListCountry(country);
    return View(country);
}
}

//This  is model class  
public partial class Country
{
    public SelectList countryList { get; set; }
    public SelectList stateList { get; set; }
}

public partial class ListCountry
{
    Entities db = new Entities();

    //This constructorof Listcounty  populate the country and state ddl 
    public ListCountry(Country country) 
    {
        string cntId1    = country.countryId;
        int id = Convert.ToInt32(cntId1);
        country.countryList = new SelectList(db.Countries.ToList(), "CountryId", "CountryName");
        if (id > 0 )
        {
            List <State> list = db.States.Where(p => p.countryId == id).ToList();
            country.stateList = new SelectList(list, "StateID", "StateName");
        }
        else
        {
            country.stateList = new SelectList(db.States.ToList(), "StateID", "StateName");
        }
    }
4

1 に答える 1