【问题标题】:Getting error in HtmlHelper/Razor in asp.net mvc-5在 asp.net mvc-5 中的 HtmlHelper/Razor 中出现错误
【发布时间】:2017-08-24 20:52:36
【问题描述】:

我已经创建了一个 cshtml 文件。当我在 Visual Studio 中运行/构建解决方案时,解决方案构建得很好,甚至功能方面(据我所知)一切似乎都在工作,但我在 Visual Studio 错误窗口中看到了一些错误。有人可以指导我为什么会看到这些错误。

@if (Utils.IsCC)
{
    <div class="CC">
        <div class="form">
            @Html.LabelFor(model => model.CreditDetails.CreditCard, htmlAttributes: new { @class = "control-label col-md-2 required" })
             // Red squiggly comes in the entire line above
        </div>
    </div>
}

错误:

方法'System.Web.Mvc.Html.LabelExtensions.LabelFor(System.Web.Mvc.HtmlHelper, System.Linq.Expressions.Expression>,System.Collections.Generic.IDictionary)' 不能从用法中推断出来。尝试明确指定类型参数。

【问题讨论】:

    标签: c# asp.net razor asp.net-mvc-5 html-helper


    【解决方案1】:

    您的 model.CreditDetails.CreditCard 的类型很难为 MVC 重新识别。

    试着把它变成普通类型,或者直接指定你应该使用的类型。

    @Html.LabelFor<string>(model => model.CreditDetails.CreditCard, htmlAttributes: new { @class = "control-label col-md-2 required" })
    

    @Html.LabelFor<ComplexObject>(model => model.CreditDetails.CreditCard, htmlAttributes: new { @class = "control-label col-md-2 required" })
    

    这就是错误试图告诉你的,但我不知道是否有更好/完美的解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-05-14
      • 2016-10-03
      • 2015-01-14
      • 1970-01-01
      • 2010-09-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多