如何在控制器中初始化值?

时间:2015-05-29 11:52:59

标签: asp.net-mvc

我有下拉列表:

@Html.DropDownListFor(m => m.Register.SelectCompany, Model.Register.Company, "Please select")

我有模特:

[Required(ErrorMessage = "*")]
[Display(Name = "Company name")]
public int SelecCompanyId{ get; set; }

public System.Web.Mvc.SelectList CompanyName{ get; set; }

当我尝试这样做时:

companyAccount.Company = (ICompany)Company.Find(model.Register.SelectCompanyId);

我收到错误

  

具有键' Register.SelectCompanyId'的ViewData项。是的   输入' System.Int32'但必须是类型   ' IEnumerable的'"}

我的课程也是:

public class Company: ICompany
{
    public int Id { get; set; }
    public string CompanyName  { get; set; }
}

0 个答案:

没有答案