0
    'public string Country;
    public List<SelectListItem> DdlCountryList { get; set; }
    public string State;
    public List<SelectListItem> DdlStateList { get; set; }
    private List<SelectListItem> _listItems;
    public string District = "District";
    public List<SelectListItem> DdlDistrictList { get; set; }
    public string Village = "Village";
    public IEnumerable<SelectListItem> DdlVillageList { get; set; }
    public string Crop = "Crop";
    public IEnumerable<SelectListItem> DdlCropList { get; set; }
    public string Year = "Year";
    public IEnumerable<SelectListItem> DdlYearList { get; set; }
    public string ProductionCode = "ProductionCode";
    public IEnumerable<SelectListItem> DdlProductionList { get; set; }
    public string Season = "Season";
    public IEnumerable<SelectListItem> DdlSeasonList { get; set; }'

> Tha Above is My Model GlobalSearchModel
> on load Iam filling Values,.. and By using Jquery change function i am calling Values how    to get the Id's of Selected DropDownValues

public ActionResult Index()
    {

        GlobalSearchModel objGlobalSearchModel = new GlobalSearchModel();
        return View(objGlobalSearchModel);
    }

これは私のコントローラーのアクションメソッドです。GlobalSearchModel()のコンストラクターでDropDownListのデフォルト値を入力しています。「選択」のように

[HttpPost]
    public ActionResult FilterMapDetails(GlobalSearchModel objGlobalSearchModel)
    {
        //Logic GoesHere then i will return values

        return View("Index", objGlobalSearchModel);

    }

上記は、送信時に呼び出された私のPostMethodです。よろしくお願いします。

4

1 に答える 1

3

ビュー モデルでは、DropDownList にバインドされ、選択した値を保持するドロップダウンごとに対応するプロパティが必要です。

例えば:

public string SelectedCountry { get; set; }
public List<SelectListItem> DdlCountryList { get; set; }

そしてあなたのビューの中で:

@Html.DropDownListFor(x => x.SelectedCountry, Model.DdlCountryList)

最後に、投稿アクションでSelectedCountryモデルのプロパティを使用するだけです:

[HttpPost]
public ActionResult FilterMapDetails(GlobalSearchModel objGlobalSearchModel)
{
    // objGlobalSearchModel.SelectedCountry will contain the selected value

    return View("Index", objGlobalSearchModel);
}
于 2013-02-28T10:46:53.320 に答える