简体   繁体   English

实体框架最佳做法下拉列表绑定

[英]Entity Framework best practices drop-down list binding

It's going to be a long one so apologies in advance. 这将是一个漫长的过程,因此提前致歉。 In an ASP.NET MVC application I am writing a partial control that is a search panel. 在ASP.NET MVC应用程序中,我正在编写作为搜索面板的部分控件。 Now this panel has 现在这个面板有

  1. classes selection drop-down but with table instead of list (table has a checkbox, and two columns with group headers - classname and no.of students) 班级选择下拉列表,但表格而不是列表(表格有一个复选框,两列带有组标题-班级名称和学生人数)
  2. year selection as dropdownlist (hopefully the easiest of all) 选择年份作为下拉列表(希望是最简单的)
  3. Indicators list with checkboxes and group headers 带有复选框和组标题的指标列表

I have defined a View model as follows 我定义了一个View模型,如下所示

public class SearchControlModel
{
    public List<Class> Classes {get; set;}
    public List<Year> Years { get; set; }
    public List<Indicator> Indicators { get; set; }
 }

Where my entities are: 我的实体在哪里:

public class Class
{

    public int classID { get; set; }
    public Nullable<int> grade { get; set; }
    public string classname { get; set; }
    public virtual ICollection<Student> Students { get; set; }
}

public class Indicator
{
    public int IndicatorID { get; set; }
    public string IndicatorDescription { get; set; }

    public virtual ICollection<Student> Students { get; set; }

}

My questions are: 我的问题是:

  1. What would be the right controls to display class and indicators (grid/table that appears as a drop-down) 什么是显示班级和指标的正确控件(网格/表格显示为下拉列表)

  2. Do I use the ado.net entities directly or through stored procedures? 是否直接或通过存储过程使用ado.net实体?

  3. If I use stored procedures, I will have to define a different entity that has only the specific properties that the stored procedure is dealing with or is there another way? 如果使用存储过程,则必须定义一个不同的实体,该实体仅具有存储过程要处理的特定属性,或者还有其他方法吗?

  4. On the View (cshtml file) how do I use these properties to bind with drop-down or table eg something like: 在视图(cshtml文件)上,如何使用这些属性与下拉列表或表格进行绑定,例如:

    • @Html.LabelFor(m => m.Classes) @ Html.LabelFor(m => m.Classes)
    • @Html.DropDownListFor(m => m.Classes, new { @class = "form-control" }) @ Html.DropDownListFor(m => m.Classes,新的{@class =“ form-control”})

In short what is the best approach to go about it? 简而言之,最好的方法是什么?

Here is a picture to clarify 这是一张要澄清的图片

在此处输入图片说明

我正在使用bootstrap-multiselect自定义控件,但仍然想知道它是否能够在其中添加详细信息/相邻列

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM