【问题标题】:ASP.NET razor Html.TextAreaASP.NET 剃须刀 Html.TextArea
【发布时间】:2013-02-22 23:58:26
【问题描述】:

1) 在使用该行编辑视图时:

    @Html.TextArea(name: "Message", rows: 10, columns: 40)

我在编译时收到此错误:

ERR: "The best overload for 'TextArea' does not have a parameter of type 'rows'"

即使存在以行和列作为参数的签名。

2) 所以我尝试使用签名: @Html.TextArea(字符串名称,对象 htmlAttributes)

如下调用函数

    @Html.TextArea(name: "Message", new { rows=10, columns=40 }

但我遇到了另一个错误:

ERR: "Named Argument Specifications must appear after all fixed arguments have been specified"

有人知道为什么以及如何解决吗?

提前谢谢你!

【问题讨论】:

    标签: asp.net textarea html-helper


    【解决方案1】:

    只需将代码更改为:

    @Html.TextArea("Message", new { rows=10, columns=40 })
    

    没有命名参数

    【讨论】:

    • 完美就是第二期的问题。第一个需要指定签名的所有标签: Html.TextArea(name:"Message", rows: 10, columns: 40, value:"", htmlAttributes: new {})
    • 似乎“列”不起作用,但“列”可以。所以如果你有和我一样的问题,试试这个。
    【解决方案2】:

    您是否尝试过从名称参数中移除名称标签?

    @Html.TextArea("Message", new { rows = 10, cols = 40})
    

    另外,textarea 上的列的 HTML 属性是 cols 而不是 columns

    【讨论】:

    • 没有标签也没关系。 cols 和 columns 都可以设置属性。谢谢。
    【解决方案3】:

    我相信您需要像这样将其添加为属性...

    @Html.TextArea("Message", new { rows=10, columns=40 })
    

    【讨论】:

      【解决方案4】:

      为什么不只是:

      @Html.TextAreaFor(model => model.Body, new { cols = 35, @rows = 3 })
      

      【讨论】:

        猜你喜欢
        • 2012-05-16
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-05-19
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多