元组问题@model Tuple<HabasPortal.Models.Profile,List<SelectListItem>>

Posted

技术标签:

【中文标题】元组问题@model Tuple<HabasPortal.Models.Profile,List<SelectListItem>>【英文标题】:Tuple Problem @model Tuple<HabasPortal.Models.Profile,List<SelectListItem>> 【发布时间】:2019-09-26 19:25:48 【问题描述】:

我在我的项目中首先使用数据库。我将保存到Profile table并从department table填写下拉列表强> 在此页面上。如何在Profile.cshtml 的视图中同时使用profile.csdepartment.cs?这是一个创建页面。

这是Profile.cs

public partial class Profile

    public int ProfileID  get; set; 
    public string Firstname  get; set; 
    public string Surname  get; set; 
    public string Department  get; set; 
    public string Office  get; set; 
    public string Location  get; set; 
    public string Username  get; set; 
    public string Email  get; set; 
    public string MobileNumber  get; set; 
    public string Title  get; set; 
    public bool Status  get; set; 
    public string Note  get; set; 
    public byte[] Image  get; set; 
    public string Gender  get; set; 
    public Nullable<System.DateTime> RecordDate  get; set; 


这是Department.cs

public partial class Department

    public int DepartmentID  get; set; 
    public string DepartmentName  get; set; 
    public string Location  get; set; 


【问题讨论】:

有人回答吗? 那么Tuple有什么问题? 我尝试了很多方法,但我得到了一个错误。如何使用 Database First 方法在视图中引用两个不同的类? 我想从Dropdownlist中的Department类中拉取数据,并选择这个传入的数据并将其传输到Profile类。 【参考方案1】:

我解决了这个问题。

ProfileController.cs

 public ActionResult Create()
    
        ViewBag.departman = new SelectList(db.Departments.ToList(), "DepartmentID", "DepartmentName");
        return View();
    

创建.cshtml

@Html.DropDownList("Department", ViewBag.departman as SelectList)

【讨论】:

以上是关于元组问题@model Tuple<HabasPortal.Models.Profile,List<SelectListItem>>的主要内容,如果未能解决你的问题,请参考以下文章

model.fit AttributeError:“元组”对象没有属性“形状”

tuple 元组

Python元组

008 tuple 元组

内置数据结构(tuple)

python基础之元组篇