asp.net-mvc – 使用MVC 4和实体框架填充DropDownList
发布时间:2020-05-23 22:15:35 所属栏目:asp.Net 来源:互联网
导读:我正在开发MVC4实体框架Application.I想要填充DropDownList,我想将Category List绑定到Dodropdown列表 IRepository Code IListCategory GetCategory(); 知识库 public IListCategory GetCategory() { return (from c in con
|
我正在开发MVC4&实体框架Application.I想要填充DropDownList,我想将Category List绑定到Dodropdown列表 IRepository Code IList<Category> GetCategory(); 知识库 public IList<Category> GetCategory()
{
return (from c in context.Categories
select c).ToList();
}
调节器 public IList<Category> GetCategory()
{
return icategoryRepository.GetCategory();
}
之后我就在这里.如何将数据绑定到Dropdownlist? 我在这里查看代码 <label for="ProductType">Product Type</label>
@Html.DropDownListFor(m => m.ProductType,new List<SelectListItem>)
我的控制器代码 public ActionResult AddProduct()
{
return View();
}
解决方法如何使用ViewBag?视图 <label for="ProductType">Product Type</label> @Html.DropDownListFor(m => m.ProductType,ViewBag.ListOfCategories) 调节器 public ActionResult AddProduct()
{
ViewBag.ListOfCategories = GetCategory();
return View();
} (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – ASP.NET MVC 2和使用WIF(Windows Identity
- asp.net – IIS 7忽略没有文件扩展名的MapPageRoute
- 勾选复选框时,禁用一些ASP.Net验证控件
- attributes – 利用属性版本控制在Swagger中利用MultipleAp
- asp.net-mvc-3 – 为什么两个类,视图模型和域模型?
- asp-classic – ASP页面中的msxml3.dll错误“80072ee2”
- asp.net – app_offline替代方案
- ASP.NET对txt文件相关操作(读
- ASP.NET CSS CSS语法问题中的类与CSSClass的区别
- ASP.NET Core中实现用户登录验证的最低配置示例代码
推荐文章
站长推荐
- asp.net-mvc – 如何使用html帮助器在asp.net mv
- asp.net – 是MemoryCache范围会话还是应用程序?
- .NET中的共享配置文件
- asp.net – Thread.CurrentPrincipal在使用WebGe
- asp.net-mvc – 返回ASP.Net Core MVC中的上一页
- asp.net – 如何防止Entity Framework将FileStre
- asp.net-mvc-3 – 在ASP.NET MVC 3中应用数据注释
- asp.net-mvc – MVC 4从基本路由中删除“home”
- asp.net-mvc – MVC捆绑:错误403
- asp.net-mvc – 如何使用MsBuild MsDeployPublis
热点阅读
