简体   繁体   中英

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. 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

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?

  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:

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

In short what is the best approach to go about it?

Here is a picture to clarify

在此处输入图片说明

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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