asp.net-mvc - 元组问题@model 元组>
问题描述
我首先在我的项目中使用数据库。我将保存到Profile 表并填写此页面上部门表的下拉列表。我如何同时使用和在视图中?这是一个创建页面。profile.cs
department.cs
Profile.cshtml
这是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; }
}
解决方案
我解决了这个问题。
配置文件控制器.cs
public ActionResult Create()
{
ViewBag.departman = new SelectList(db.Departments.ToList(), "DepartmentID", "DepartmentName");
return View();
}
创建.cshtml
@Html.DropDownList("Department", ViewBag.departman as SelectList)
推荐阅读
- shell - 删除超过 2 年的大型媒体文件的脚本,其中删除了同名和日期的文本文件
- python - 如何在 Python 中保存元组对象中的数据?
- go - 如何查找未分配的结构字段
- c# - 运行多个进程、C++ 和 Excel 导致的错误
- ruby - ruby - 将http响应正文从xml转换为哈希的问题 - 缺少属性引用错误
- shell - 如果为真,则比较 csv 文件中的值,然后在同一文件中获取另一个值
- javascript - 如何使用 javascript 更新 JSON 对象而不删除旧值
- angular - ADB2C AcquireTokenSilent 行为
- python - Tensorflow和Keras问题ValueError:检查输入时出错:预期dense_9_input具有形状(24,)但得到形状为(0,)的数组
- python - 在 Python 中查找具有不同输出列表长度的不同列表的所有可能组合(不是重复的)