我的 PartialView DropDownListFor 出现错误的问题:
The ViewData item that has the key PlanId is of type System.int32 but must be of type
IEnumerable<SelectListItem>
@Html.DropDownListFor(model => model.PlanId, (SelectList)ViewBar.PlanNameSelectList, new {@class = "short" })
当我转到最初保存此代码的页面时,不会弹出此错误。只要我取出代码中的 DropDownListFor 元素,我所做的就是将之前与另一个 partialView 一起工作的代码的核心部分删掉。那个partialView我不需要它们,但是现在我需要它们,问题就来了。
我将不胜感激任何可以帮助我解决这个问题的帮助。其他资源,如对部分的调用如下
@Html.Partial("location", new MAO.Models.ViewModels.CreateTemplateModel{})
这是模型
public class CreateTemplateModel {
[Required(ErrorMessage = "{0} is required.")]
[RegularExpression("^[0-9]+$", ErrorMessage="Template Id can only contain numbers")]
[Display(Name = "Template ID")]
public string TNumber { get; set; }
[Required(ErrorMessage = "{0} is required.")]
[RegularExpression("^.[0-9]{4}(-[0-9]{3})?$", ErrorMessage = "H# Must follow either @XXXX or @XXXX-XXX pattern")]
[Display(Name = "HNumber")]
public string HNumber { get; set; }
[RequiredIfOtherIsEmpty("NewPlanName", ErrorMessage = "Please enter a Plan Name")]
[Display(Name = "Select Existing Plan Name")]
public int PlanId { get; set; }
[MaxLength(500, ErrorMessage="{0} can't be longer than 500 characters")]
[Display(Name = "Enter New Plan Name")]
public string NewPlanName { get; set; }
[RequiredIfOtherIsEmpty("NewParentOrganization", ErrorMessage = "Please enter a Parent Organization")]
[Display(Name = "Select Existing Parent Organization")]
public string ParentOrganization { get; set; }
[MaxLength(500, ErrorMessage = "{0} can't be longer than 500 characters")]
[Display(Name = "Enter New Parent Organization")]
public string NewParentOrganization { get; set; }
[Required(ErrorMessage = "{0} is required.")]
public int TemplateTypeId { get; set; }
}
有一个很长的控制器,所以我不打算发布它。如果控制器的某些部分会有所帮助,我可以发布这些部分以及我可能忘记包含的其他任何内容