项的错误,我有一个包含下拉列表,从一台叫做月取值,在视图中使用这个局部视图称为PSR值不能为空。参数名:在MVC5
我在控制器传递的对象的局部视图:
public ActionResult PSR()
{
var PSRS = _context.PSRs.ToList();
var months = _context.Months.ToList();
var viewModel = new PSRViewModel
{
PSRs = PSRS,
Months = months
};
return View(viewModel);
}
内部的局部视图:
@model Project.ViewModels.PSRViewModel
<h5> Month </h5>
<div class="form-group">
@Html.LabelFor(m => m.Month.month)
@Html.DropDownListFor(m => m.Month.month, new SelectList(Model.Months, "Id", "month"), "--Select Month--", new { @class = "form-control" })
</div>
而且这里面PSR观点:
@model List<Project.ViewModels.PSRViewModel>
@{
ViewBag.Title = "PSR";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<div>
@Html.Partial("~/Views/Doctors/_AddPSR.cshtml", new Project.ViewModels.PSRViewModel()) </div>
那么为什么运行PSR视图时出现这个错误呢?即使传递对象到视图
这是ViewModel类代码:
namespace Project.ViewModels
{
public class PSRViewModel
{
public PSR PSR { get; set; }
public List<PSR> PSRs { get; set; }
public Doctor Doctor { get; set; }
public List<Month> Months { get; set; }
public Month Month { get; set; }
}
}
我应该把这个控制器?
var months = new List<Month> {
};
UPDATE: 月模型
namespace Project.Models
{
public class Month
{
public int Id { get; set; }
public string month { get; set; }
}
}
什么PSRViewModel.Month.month?我们可以看到这个类的定义吗? – Steve
是的,我把它.. –
感觉就像你想循环你的模型,调用@ html.partial(“VIEWNAME”,模型[i]) – Steve