asp.net-mvc – 使用MVC 4和实体框架填充DropDownList
发布时间:2020-12-16 00:04:45 所属栏目:asp.Net 来源:网络整理
导读:我正在开发MVC4实体框架Application.I想要填充DropDownList,我想将Category List绑定到Dodropdown列表 IRepository Code IListCategory GetCategory(); 知识库 public IListCategory GetCategory() { return (from c in context.Categories select c).ToList
我正在开发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-3 – MVC3未终止字符串常量语法错误
- asp.net – DropDownList OnSelectedIndexChange到第0个索引
- entity-framework-core – 实体框架Core 2.0许多表中公共属
- 处理ASP.Net MVC中的过期标题
- asp.net – MVC4上的_layout.cshtml的@model?
- asp.net – 使用JavaScript重新排列的ListBox元素导致回发时
- asp.net – GCFrame在WinDBG中输出!clrstack命令意味着什么
- asp.net – 动态编译的文件在.NET中使用csc.exe吗?
- asp.net在页面之间传递类的实例
- asp.net – 如何在Azure网站上设置machineKey
推荐文章
站长推荐
- asp.net-core – 为Microsoft.CodeAnalysis.Comm
- asp.net – 如何判断Application_Error中是否有R
- asp.net-mvc – 我可以使用MVC全局动作过滤器来禁
- asp.net – 从C#代码增加Http Runtime MaxReques
- asp.net – 使用DataContext静态变量
- asp.net – e.CommandArgument for asp按钮不工作
- .net – Autofac SignalR
- asp.net-mvc-4 – 缺少尾部斜杠的MVC错误行为的解
- asp.net-mvc – 单元测试自定义模型Binder – 假
- asp.net-mvc – ASP.NET MVC Action被调用两次
热点阅读