我在mvc中有两个项目。

在其中之一中,我使用以下代码:

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


它可以正常工作,因为该项目具有labelfor的扩展方法,如下所示:

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)


html - html.labelfor不接受任何CSS类作为输入-LMLPHP

但是在另一个项目中,当我使用上面的代码时,我的意思是:

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


我收到此错误:

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


在对象浏览器中,我找不到其他项目具有的上述扩展名。您可以在此处看到:

html - html.labelfor不接受任何CSS类作为输入-LMLPHP

问题出在哪里?我应该更改MVC版本吗?

这是查看代码:

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

}


最好的祝福

最佳答案

最后,我从nuget中删除了asp.mvc并再次安装。

关于html - html.labelfor不接受任何CSS类作为输入,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/31738471/

10-10 12:41