首先我正在关注找到here的演示,并且我已正确安装了软件包。我遇到了与本文here相同的问题,但我能够使用提供的答案进行修复。我清理了项目,重建了它,并尝试关闭Visual Studio并再次打开它,但没有运气。我收到以下错误消息,我也将在下面显示我的查看代码:
CS1928:'System.Web.Mvc.HtmlHelper'不包含'EditorFor'的定义和最佳扩展方法重载'System.Web.Mvc.Html.EditorExtensions.EditorFor(System.Web.Mvc.HtmlHelper, System.Linq.Expressions.Expression>,string,object)'有一些无效的参数
查看:
@using (Html.BeginForm("Contact", "Home", FormMethod.Post, new { @class = "form-horizontal" }))
{
@Html.ValidationSummary(true)
<div class="form-group">
@Html.LabelFor(model => model.Name, "Name:", htmlAttributes: new { @class = "col-sm-4 control-label" })
<div class="col-sm-8">
@Html.EditorFor(model => model.Name, true, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Name)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Email, "Email:", htmlAttributes: new { @class = "col-sm-4 control-label" })
<div class="col-sm-8">
@Html.EditorFor(model => model.Email, true, new { id = "email", htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Email)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.PhoneNumber, "Phone Number:", htmlAttributes: new { @class = "col-sm-4 control-label" })
<div class="col-sm-8">
@Html.EditorFor(model => model.PhoneNumber, true, new { id = "phoneNumber", htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.PhoneNumber)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Topic, "Topic:", htmlAttributes: new { @class = "col-sm-4 control-label" })
<div class="col-sm-8">
@Html.EditorFor(model => model.Topic, true, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Topic)
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Subject, "Subject:", htmlAttributes: new { @class = "col-sm-4 control-label" })
<div class="col-sm-8">
@Html.DropDownListFor(model => model.Subject, true, (SelectList)ViewBag.subject, "--Select--", new { id = "subjectList", @class = "form-control" })
@Html.ValidationMessageFor(model => model.Subject)
</div>
</div>
<div class="form-group" style="margin-top: 30px;">
<div class="col-sm-offset-4 col-sm-8">
<input type="submit" class="btn btn-primary" value="Submit" />
<input type="reset" class="btn btn-default" value="Reset" />
</div>
</div>
}
的Web.config:
<configSections>
<sectionGroup name="system.web.webPages.razor" type="System.Web.WebPages.Razor.Configuration.RazorWebSectionGroup, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<section name="host" type="System.Web.WebPages.Razor.Configuration.HostSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
<section name="pages" type="System.Web.WebPages.Razor.Configuration.RazorPagesSection, System.Web.WebPages.Razor, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" />
</sectionGroup>
<system.web.webPages.razor>
<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" />
<pages pageBaseType="System.Web.Mvc.WebViewPage">
<namespaces>
<add namespace="System.Web.Mvc" />
<add namespace="System.Web.Mvc.Ajax" />
<add namespace="System.Web.Mvc.Html" />
<add namespace="System.Web.Optimization"/>
<add namespace="System.Web.Routing" />
<add namespace="HomeworkHelpers" />
</namespaces>
</pages>