我正试图将一个局部视图中的子对象传递到另一个视图,但总是出现错误。有谁可以帮我解决这个问题?T.T
"传递到字典中的模型项类型为 'Application.Models.PetModel',但该字典需要类型为 'Application.Models.Calendar' 的模型项"
主模型
public class PetModel
{
public string Name { get; set; }
public long SpeciesID { get; set; }
public long BreedID { get; set; }
public Calendar DOB { get; set; }
}
子模型
public class Calendar
{
public int Day { get; set; }
public int Month { get; set; }
public int Year { get; set; }
public DateTime DateObj
{
get
{
if (Day != 0 && Month != 0 && Year != 0)
{
return new DateTime(Year, Month, Day);
}
return DateTime.Now;
}
set
{
if (value != null)
{
Day = value.Day;
Month = value.Month;
Year = value.Year;
}
}
}
}
主视图
@model Application.Models.PetModel
@using (Html.BeginForm("CatchPetContent", "Quote",Model))
{
@Html.Partial("PetDetailsContent", Model)
<input type="submit" value="submit" />
}
PetDetailsContent Partial View
@model Application.Models.PetModel
@Html.TextBoxFor(x => x.Name)
@Html.DropDownListFor(x => x.SpeciesID, (IEnumerable<SelectListItem>)ViewData["TypeList"], "--Please Select--")
@Html.DropDownListFor(x => x.BreedID, (IEnumerable<SelectListItem>)ViewData["BreedList"], "--Please Select--")
@Html.RenderPartial("UserControl/Calendar", Model.DOB)
日历局部视图
@model Application.Models.Calendar
@Html.TextBoxFor(x => x.Day)
@Html.TextBoxFor(x => x.Month)
@Html.TextBoxFor(x => x.Year)