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);
    }

这是我的控制器的 Action 方法,我在 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 回答