将默认值附加到dropdownlistfor - MVC 4 razor

时间:2014-02-21 15:35:16

标签: c# asp.net-mvc-4 razor dropdownlistfor

如何使用下面的代码将默认值附加到我的下拉列表

[AcceptVerbs(HttpVerbs.Get)]
    public ActionResult GetCitiesByStateId(int stateId)
    {
        if (stateId==0)
        {
            throw new ArgumentNullException("stateId");
        }

        var x = _repository.GetAllCitiesByStateId(stateId);
        var result = (from s in x
                      select new
                      {
                          id = s.id,
                          name = s.CityName
                      }).ToList();

        return Json(result, JsonRequestBehavior.AllowGet);
    }

我的观看代码如下所示:

 @Html.DropDownListFor(x => x.City.ID, Model._Cities)
 @Html.ValidationMessageFor(x => x.City)

感谢期待

0 个答案:

没有答案