下拉框绑定


开发工具与关键技术: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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值