2

私はここでEntity Frameworkを初めて使用し、単純なリストボックスコントロールを作成しようとしましたが、リストボックスが空になりました。ここで私が間違っていたことを教えてください。

DAL (エンティティ フレームワーク):

namespace DataAccess
{
using System;
using System.Collections.Generic;

public partial class Client
{
    public Client()
    {
        this.AnotoPGCFiles = new HashSet<AnotoPGCFile>();
        this.Client1 = new HashSet<Client>();
        this.Client11 = new HashSet<Client>();
        this.ClientBillingSetups = new HashSet<ClientBillingSetup>();
        this.ClientDataStores = new HashSet<ClientDataStore>();
        this.ClientDepartments = new HashSet<ClientDepartment>();
        this.ClientFileNames = new HashSet<ClientFileName>();
        this.ClientReports = new HashSet<ClientReport>();
    }

    public int ID { get; set; }
    public string Name { get; set; }
    public string ContactName { get; set; }
    public string ContactEmail { get; set; }
    public string PathToLogo { get; set; }
    public bool Disabled { get; set; }
    public System.DateTime Created { get; set; }
    public int TimeZoneID { get; set; }

    public virtual AnotoLicensePool AnotoLicensePool { get; set; }
    public virtual ICollection<AnotoPGCFile> AnotoPGCFiles { get; set; }
    public virtual ICollection<Client> Client1 { get; set; }
    public virtual Client Client2 { get; set; }
    public virtual ExternalSystemDemographicConfiguration  ExternalSystemDemographicConfiguration { get; set; }
    public virtual ICollection<Client> Client11 { get; set; }
    public virtual Client Client3 { get; set; }
    public virtual TimeZone TimeZone { get; set; }        
 }
}

コントローラ:

public ActionResult Index()
 {
  ViewData["ReportFormat"] = "html";
  ViewBag.Title = "Home Page";

  var db = new DataAccess.Client();
  IEnumerable<SelectListItem> clients = db.Client1
        .Select(c => new SelectListItem
        {
              Value = c.ID.ToString(),
              Text = c.Name
        });

  ViewBag.Clients = clients;
  return View();
 }

意見:

@Html.ListBox("ListClients", (IEnumerable<SelectListItem>) ViewBag.Clients)
4

1 に答える 1