0

I have two projects in mvc .

in one of them i use this code :

 @Html.LabelFor(model => model.Subject, new { @class = "control-label col-lg-2" })

And it works correctly because the project has an extension method for labelfor as you can see here :

public static System.Web.Mvc.MvcHtmlString LabelFor<TModel, TValue>(this System.Web.Mvc.HtmlHelper<TModel> html, System.Linq.Expressions.Expression<Func<TModel,TValue>> expression, object htmlAttributes)

enter image description here

But in the other project when i use the above code i mean :

@Html.LabelFor(model => model.Name, new { @class = "control-label col-lg-2" })

I got this error :

CS1928: 'System.Web.Mvc.HtmlHelper<DomainClass.Task>' does not contain a definition for 'LabelFor' and the best extension method overload 'System.Web.Mvc.Html.LabelExtensions.LabelFor<TModel,TValue>(System.Web.Mvc.HtmlHelper<TModel>, System.Linq.Expressions.Expression<System.Func<TModel,TValue>>, string)' has some invalid arguments

In the object browser i couldn't find the above extension that the other project has.as you can see here :

enter image description here

where is the problem?should i change the mvc version ?

here is the view code :

@model DomainClass.Task
@using System.Web.Mvc.Html;
@{
    ViewBag.Title = "Create";
    Layout = "~/Areas/Admin/Views/Shared/_LayoutPage.cshtml";
}


@using (Html.BeginForm("Create", "Task", FormMethod.Post, new { id = "form", enctype = "multipart/form-data" ,@class = "cmxform form-horizontal tasi-form" }))

{

    <div class="row">
        <div class="col-lg-12">
            <section class="panel panel-default">
                <div class="panel-heading" style="font-weight: bold">ثبت نمایشگاه </div>
                <div class="panel-body">
                    <div class=" form">

                        <div class="form-group">
                            @Html.LabelFor(model => model.Name, new { @class = "control-label col-lg-2" })

                            <div class="col-lg-10">
                                @Html.TextBoxFor(model => model.Name, new { @class = "form-control myfont" })
                                @Html.ValidationMessageFor(i => i.Name, "", new { @class = "validation" })
                            </div>
                        </div>

                        <div class="form-group">
                            @Html.LabelFor(model => model.StartDate, new { @class = "control-label col-lg-2" })

                            <div class="col-lg-10">
                                @Html.TextBoxFor(model => model.StartDate, new { @class = "form-control myfont" })
                                @Html.ValidationMessageFor(i => i.StartDate, "", new { @class = "validation" })
                            </div>
                        </div>
                          <div class="form-group">
                            @Html.LabelFor(model => model.FinishDate, new { @class = "control-label col-lg-2" })

                            <div class="col-lg-10">
                                @Html.TextBoxFor(model => model.FinishDate, new { @class = "form-control myfont" })
                                @Html.ValidationMessageFor(i => i.FinishDate, "", new { @class = "validation" })
                            </div>
                        </div>
                        <div class="form-group">
                            @Html.LabelFor(model => model.Duration, new { @class = "control-label col-lg-2" })

                            <div class="col-lg-10">
                                @Html.TextBoxFor(model => model.Duration, new { @class = "form-control myfont" })
                                @Html.ValidationMessageFor(i => i.Duration, "", new { @class = "validation" })
                            </div>
                        </div>

                        <div class="form-group">
                            @Html.LabelFor(model => model.Importance, new { @class = "control-label col-lg-2" })

                            <div class="col-lg-10">
                                @Html.TextAreaFor(model => model.Importance, new { @class = "form-control myfont" })
                                @Html.ValidationMessageFor(i => i.Importance, "", new { @class = "validation" })
                            </div>
                        </div>

                        <div class="form-group">
                            @Html.LabelFor(model => model.DateOfSubmit, new { @class = "control-label col-lg-2" })

                            <div class="col-lg-10">
                                @Html.TextAreaFor(model => model.DateOfSubmit, new { @class = "form-control myfont" })
                                @Html.ValidationMessageFor(i => i.DateOfSubmit, "", new { @class = "validation" })
                            </div>
                        </div>

                         <div class="form-group">
                            @Html.LabelFor(model => model.Type, new { @class = "control-label col-lg-2" })

                            <div class="col-lg-10">
                                @Html.TextAreaFor(model => model.Type, new { @class = "form-control myfont" })
                                @Html.ValidationMessageFor(i => i.Type, "", new { @class = "validation" })
                            </div>
                        </div>





                        <div class="form-group">
                            <div class="col-lg-offset-2 col-lg-10">
                                <button class="btn btn-success" type="submit">ثبت اطلاعات</button>
                            </div>
                        </div>
                    </div>

                </div>
            </section>
        </div>
    </div>

}

Best regards

Ehsan Akbar
  • 6,977
  • 19
  • 96
  • 180
  • The error could be caused by other invalid code in the view. Try commenting out everything except the `@model ...` definition and see if the same error is thrown –  Jul 31 '15 at 05:40
  • @StephenMuecke i added the view code – Ehsan Akbar Jul 31 '15 at 05:42
  • Cant even find `@Html.LabelFor(model => model.Subject, ...)` in your view :) –  Jul 31 '15 at 05:45
  • @StephenMuecke i can find ,what do you mean? – Ehsan Akbar Jul 31 '15 at 05:47
  • The only `LabelFor()` methods I can find are for properties `Name`, `StartDate`, `FinishDate`, `Duration`, `Importance`, `DateOfSubmit` and `Type` - nothing for `Subject` - have you shown the correct view? –  Jul 31 '15 at 05:56
  • @StephenMuecke sorry it was my fault.i changed it ,all html.labelfor have error. – Ehsan Akbar Jul 31 '15 at 05:58
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/84762/discussion-between-ehsan-akbar-and-stephen-muecke). – Ehsan Akbar Jul 31 '15 at 05:59

1 Answers1

0

I finally remove my asp.mvc from nuget and install it again .and it works fine.

Ehsan Akbar
  • 6,977
  • 19
  • 96
  • 180