我是 ASP .NET 的新手,尤其是 ASP .Net MVC3 Razor...
我在 MVC3 Razor 中为客户和高管创建了视图。
我所做的是第一次创建了名为 Clients.cs 的模型
namespace MVCInetClient.Model
{
[Table("tbl_Customer")]
public class Clients
{
[Required,Key,DatabaseGenerated(DatabaseGeneratedOption.None)]
[Display(Name = "Client ID")]
public int ClientId { get; set; }
[Required]
[Display(Name = "Client Name")]
public string ClientName { get; set; }
[Required]
[Display(Name = "Executive Name")]
public string ExecutiveName { get; set; }
[Required]
[Display(Name = "Contact Name")]
public string ContactPerson { get; set; }
[Display(Name = "Address")]
public string Add1 { get; set; }
[Display(Name = " ")]
public string Add2 { get; set; }
[Display(Name = " ")]
public string Add3 { get; set; }
[Display(Name = "Pincode")]
public string Pin { get; set; }
[Display(Name = "State")]
public string State { get; set; }
[Display(Name = "Country")]
public string Country { get; set; }
[Display(Name = "Phone")]
public string Phone { get; set; }
[Required]
[StringLength(10)]
[RegularExpression("\\d+")]
[Display(Name = "Mobile")]
public string Mobile { get; set; }
[Display(Name = "Fax")]
public string Fax { get; set; }
[Display(Name = "Email")]
public string Email { get; set; }
[Display(Name = "Website")]
public string Web { get; set; }
}
public class ClientsDbContext : DbContext
{
public DbSet<Clients> Clients { get; set; }
public DbSet<Executives> Executives{ get; set; }
}
}
之后,我使用脚手架选项创建了名为 ClientsController 的控制器,
Template : Controller With Read/Write actions and Views, using Entity Framework
Model Class : Clients (MVCInetClient.Models)
Data Context Class : ClientsDbContext (MVCInetClient.Models)
它自动创建视图创建、编辑、索引、删除,并且工作正常。
同样,我为名为 Executives.cs 的模型做了
namespace MVCInetClient.Models
{
[Table("tbl_Executive")]
public class Executives
{
[Required, Key, DatabaseGenerated(DatabaseGeneratedOption.None)]
[Display(Name = "Executive ID")]
public int ExecutiveId { get; set; }
[Required]
[Display(Name = "Executive Name")]
public string ExecutiveName { get; set; }
[Display(Name = "Address")]
public string Add1 { get; set; }
[Display(Name = " ")]
public string Add2 { get; set; }
[Display(Name = " ")]
public string Add3 { get; set; }
[Display(Name = "Pincode")]
public string Pin { get; set; }
[Display(Name = "State")]
public string State { get; set; }
[Display(Name = "Country")]
public string Country { get; set; }
[Display(Name = "Phone")]
public string Phone { get; set; }
[Required]
[StringLength(10)]
[RegularExpression("\\d+")]
[Display(Name = "Mobile")]
public string Mobile { get; set; }
[Display(Name = "Email")]
public string Email { get; set; }
}
public class ExecutivesDbContext : DbContext
{
public DbSet<Executives> Executives { get; set; }
}
}
这在所有视图中也工作正常(创建、编辑、删除)
我需要的是,我需要客户视图中的主管姓名下拉列表,而不是编辑器字段。
我看了一些教程,但我很困惑...请帮我解决它...