0

First off I'm following the demo found here and I have installed the packages correctly. I had the same issue as this article here but I was able to fix it using the answer provided. I cleaned the project, rebuilt it, and also tried closing Visual Studio and opening it again but no luck. I'm getting the following error message and I will show my View code below as well:

CS1928: 'System.Web.Mvc.HtmlHelper' does not contain a definition for 'EditorFor' and the best extension method overload 'System.Web.Mvc.Html.EditorExtensions.EditorFor(System.Web.Mvc.HtmlHelper, System.Linq.Expressions.Expression>, string, object)' has some invalid arguments

View:

@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>

Community
  • 1
  • 1
DarthVegan
  • 1,719
  • 7
  • 25
  • 42
  • That error has got nothing to do with jquery unobtrusive validation. Its possibly a problem with the `web.config` file. Can you include the `` section –  Dec 05 '14 at 02:22
  • I agree with Stephen, jquery unobtrusive validation is for us to do validation, maybe you can remove the Helper and install again from Nuget. Still can not than has to refer to config file. – Harris Yer Dec 05 '14 at 02:52
  • @StephenMuecke I pasted the web.config code above and is it just web.mvc.html or does it have helper in the name? – DarthVegan Dec 05 '14 at 02:53
  • No, that looks fine. Your using MVC 5.2. Have you done an update? Whats the version of Razor in ``? –  Dec 05 '14 at 02:59
  • @StephenMuecke I added the configsections as well. I have only installed the nuget package to get the unobtrusive jquery working and that is it so far – DarthVegan Dec 05 '14 at 03:21
  • That looks OK too (I've seem some similar questions where updates have been done and there is a version mismatch. I would suggest creating new solution, add a simple view model and view, and try using `@Html.EditorFor()` to see if you still get the error. –  Dec 05 '14 at 03:28
  • @StephenMuecke I did what you suggested and I'm getting the same error. What can I do to fix this? Just to reiterate I have already uninstalled the package and installed it again and no change – DarthVegan Dec 05 '14 at 03:36
  • Don't know, other that putting that error message in the address bar and hope someone else has a solution. –  Dec 05 '14 at 03:39

0 Answers0