C# 脚手架模型不显示行中的特定列
我有下表: 以及它的模型:C# 脚手架模型不显示行中的特定列,c#,razor,asp.net-core,model,razor-pages,C#,Razor,Asp.net Core,Model,Razor Pages,我有下表: 以及它的模型: public class Movie { public int Id { get; set; } public string Title { get; set; } public int Duration { get; set; } public enum Ratings { G = 1, PG = 2, PG13 = 3, R = 4 }
public class Movie
{
public int Id { get; set; }
public string Title { get; set; }
public int Duration { get; set; }
public enum Ratings
{
G = 1,
PG = 2,
PG13 = 3,
R = 4
}
public virtual Ratings MaturityRating { get; set; }
public ICollection<Screening> Screenings { get; set; }
}
问题是,脚手架表单在下拉列表中显示电影及其ID,并且应该显示电影的标题:
如何更改此选项?在控制器中创建一个列表以填充下拉列表。如果ViewBag对象名称与将用于下拉项的模型属性名称匹配,则该对象名称 看法
我相信这是针对MVC的,它是如何与Razor页面一起工作的?我不知道它是Razor页面,您能同时显示您的cshtml文件吗?
public class Screening
{
public int Id { get; set; }
public DateTime Date { get; set; }
public int Room { get; set; }
public int Seats { get; set; }
[ForeignKey("Movie")]
public virtual int MovieId { get; set; }
public virtual Movie Movie { get; set; }
}
@*DropDownList*@
<div class="form-group">
@Html.LabelFor(model => model.Movie, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(model => model.Movie, null, "Please Select", new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.Movie, "", new { @class = "text-danger" })
</div>
</div>
ViewBag.Movie = db.Movies.GetAll().Select(x=> new SelectListItem() { Name = x.Name, Value x.Id});