我有两个模型,我想在一个视图中显示。所以我正在使用
@Html.Partial
这是我的第一个模型。
public partial class graduandModel :BaseNopEntityModel
{
public graduandModel()
{
this.AvailableCeremony = new List<SelectListItem>();
}
public string first_name { get; set; }
public string middle_name { get; set; }
public string last_name { get; set; }
public int student_id { get; set; }
public int ceremony_id { get; set; }
public DateTime ceremony_date { get; set; }
public int graduand_id { get; set; }
public IList<SelectListItem> AvailableCeremony { get; set; }
public graduandDegreeModel graduandDegreeGroup { get; set; }
}
这是我的第二个模型。
public class graduandDegreeModel
{
public graduandDegreeModel()
{
this.AvailableDegree = new List<SelectListItem>();
}
public string degree_id { get; set; }
public int graduand_id { get; set; }
public string degree_name { get; set; }
public IList<SelectListItem> AvailableDegree { get; set; }
}
这是 mu 控制器
public ActionResult CheckData(int ceremony_id, string first_name, string middle_name, string last_name)
{
graduandModel model = new graduandModel();
graduandDegreeModel model_1 = new graduandDegreeModel();
var graduandList = _graduandService.GetGraduandByStudent(ceremony_id, first_name, middle_name, last_name);
if (graduandList.Count != 0)
{
model.ceremony_id = ceremony_id;
model.first_name = first_name;
model.middle_name = middle_name;
model.last_name = last_name;
// var degreeList = "";
foreach (var c in graduandList)
{
var degreeList = _graduandDegreeService.getAllDegreeIdBtGraduandId(c.graduand_id);
foreach (var d in degreeList)
{
model_1.AvailableDegree.Add(new SelectListItem() { Text = d.Degree.degree_name, Value = d.degree_id });
}
}
}
return View(model);
}
这是我的看法
@{
Layout = "~/Views/Shared/_ColumnsThree.cshtml";
}
@model graduandModel
@using Nop.Web.Models.Hire;
@using Nop.Web.Framework;
@using Telerik.Web.Mvc.UI;
@using System.Linq;
@using (Html.BeginForm())
{
<table >
<tr>
<td >
Ceremony :
</td>
<td>
Ceremony at @Model.ceremony_date
</td>
</tr>
<tr>
<td >
Name :
</td>
<td >
@Model.first_name @Model.middle_name @Model.last_name
</td>
</tr>
</table>
<div>
@Html.Partial("_DegreeDetailsByGraduand", Model.graduandDegreeGroup)
</div>
}
这是我的部分观点
@{
Layout = "~/Views/Shared/_ColumnsThree.cshtml";
}
@model graduandDegreeModel
@using Nop.Web.Models.Hire;
@using Nop.Web.Framework;
@using Telerik.Web.Mvc.UI;
@using System.Linq;
<table >
<tr>
<td >
AAAAAA
</td>
<td>
@Html.DropDownListFor(model => model.degree_id, Model.AvailableDegree)
@* @Html.ValidationMessageFor(model => model.ceremony_id)*@
</td>
</tr>
</table>
有错误
The model item passed into the dictionary is of type 'Nop.Web.Models.Hire.graduandModel', but this dictionary requires a model item of type 'Nop.Web.Models.Hire.graduandDegreeModel'.
我怎么能爱它???