开发工具与关键技术:VS
作者:胡宁淇
撰写时间:2019年6月23日
MVC模式中我们给下拉框绑定数据可以通过在控制器中写方法查询数据库中的数据,然后绑定给下拉框,方法如下
我们首先在控制器中写出linq查询,查出下拉框中的数据
//国家查询
public ActionResult SelectCountry() {
List listCountry = (from tbCountry in myModel.D_Country
select new Select {
id=tbCountry.CountryID,
text=tbCountry.Country
}).ToList();
return Json(listCountry,JsonRequestBehavior.AllowGet);
}
//民族查询
public ActionResult SelectEthnic(int CountryId) {
List listEthnic = (from tbEthnic in myModel.D_Ethnic
where
tbEthnic.CountryID==CountryId
select new Select {
id=tbEthnic.EthnicID,
text=tbEthnic.EthnicName
}).ToList();
return Json(listEthnic,JsonRequestBehavior.AllowGet);
}
//病人类别
public ActionResult SelectP