Asp.net MVC EditorFor"类型' System.Object'在未引用的程序集中定义"错误

时间:2015-07-06 08:46:20

标签: c# asp.net asp.net-mvc asp.net-mvc-4 razor

@using (Html.BeginForm("Index", "Employees", FormMethod.Post, new { encType = "multipart/form-data", name = "EmployeeForm" }))
{
<table class="table table-bordered table-condensed table-striped">
    <tr>
        <th>
            Name
        </th>
        <th>
            Surname
        </th>
        <th>
            ID Number
        </th>
        <th>
            Email
        </th>
        <th>
            Birthdate
        </th>
        <th>
            Action
        </th>
    </tr>
    @Html.EditorFor(model => model.Employees)
</table>
}

第32行:@ Html.EditorFor(model =&gt; model.Employees)给出以下错误

CS0012: The type 'System.Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'.

我在另一个没有出现此错误的项目中使用了这种类似的方法。

1 个答案:

答案 0 :(得分:17)

在web.config中查找:

 int count=imageArray.length();
    for(int i=0;i<count;){
        setupView(i,count,parentView);
        i=i+3;
    }

  private View setupView(int currentPos,int totalCount,View parentView) {
       int itemCount = currentPos;
       LinearLayout columnOdd = (LinearLayout) parentView.findViewById(R.id.column_odd);
       LinearLayout columnEven = (LinearLayout) parentView.findViewById(R.id.column_even);
       LinearLayout columnCenter = (LinearLayout) parentView.findViewById(R.id.column_center);
       View itemView = inflater.inflate(R.layout.custom_view, null);
       columnEven.addView(itemView);
       itemCount++;
       if(itemCount<totalCount){
           itemView = inflater.inflate(R.layout.custom_view, null);
           columnOdd.addView(itemView);
       }
      itemCount++;
      if(itemCount<totalCount){
           itemView = inflater.inflate(R.layout.custom_view, null);
           columnCenter.addView(itemView);
      }
  }

添加<compilation debug="true" targetFramework="4.5"/> 程序集,如下所示:

System.Runtime

这通常是由MVC和PCL引起的,详见以下文章:

The type ‘System.Object’ is defined in an assembly that is not reference (MVC + PCL issue)