【问题标题】:Visual Studio Autocomplete for Html Helpers用于 Html 帮助程序的 Visual Studio 自动完成
【发布时间】:2014-02-27 16:20:48
【问题描述】:

在 Razor 中编写 Html 辅助元素时,例如:

@Html.LabelFor(m => m.MyProperty, new { @class="col-sm-2 control-label" })

或者

@Html.TextBoxFor(m => m.MyProperty, new { @class="form-control", placeholder="Property" })

Visual Studio 正在将“new {”转换为“new object {”,但这是无效的。为什么智能感知会这样做?我错过了什么吗?

【问题讨论】:

  • 它也对我有用。我只是删除了object 部分并继续我的一天。

标签: c# visual-studio razor intellisense


【解决方案1】:

我想这是因为 this 特定的重载签名:

public static MvcHtmlString TextBoxFor<TModel, TProperty>(
    this HtmlHelper<TModel> htmlHelper,
    Expression<Func<TModel, TProperty>> expression,
    Object htmlAttributes
)

毕竟,htmlAttributes 必须有某种 种类型声明,而Object 是他们选择的最小公分母,因为最初这些方法时dynamic 不可用写的。

这确实有点烦人,但 Intellisense 只是在做它的工作 :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-12
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多