如何使用下面的代码将默认值附加到我的下拉列表
[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)
感谢期待