gpt4 book ai didi

.net - MVC Html.TextArea 过载问题

转载 作者:行者123 更新时间:2023-12-04 22:02:02 24 4
gpt4 key购买 nike

我在 MVC View 中有一个表单,其中包含许多文本框、下拉列表和文本区域。我正在使用 HTML 帮助程序创建这些控件,包括在适当的地方使用 View Data 预先填充它们,并通过 htmlAttributes 参数应用样式。

这适用于 TextBox 控件和 DropDownLists 等,但是当我将 htmlAttributes 添加到 TextArea 时,它停止工作,声称最佳重载方法有一些无效参数,失败的代码是:

Html.TextArea("Description", ViewData["Description_Current"], new { @class = "DataEntryStd_TextArea" })

由此产生的错误是:

'System.Web.Mvc.HtmlHelper' does not contain a definition for 'TextArea' and the best extension method overload 'System.Web.Mvc.Html.TextAreaExtensions.TextArea(System.Web.Mvc.HtmlHelper, string, string, object)' has some invalid arguments



为了比较,工作正常的 TextBox 调用是:
Html.TextBox("TelephoneNumberAlternate", ViewData["TelephoneNumberAlternate"], new { @class = "DataEntryStd_TextBox" })

我尝试明确引用 TextAreaExtensions.TextArea 并包含 HtmlHelper 参数,但这没有区别。

有关信息,TextArea 调用在没有 htmlAttributes 参数的情况下工作正常。此外,我尝试为类属性指定名称/值字典,但这遇到了完全相同的问题。

任何想法我做错了什么?

最佳答案

这些错误消息并不能告诉您其中一个参数不匹配,这总是使我感到困惑。

你有试过吗?

Html.TextArea("Description", ViewData["Description_Current"].ToString(), new { @class = "DataEntryStd_TextArea" })

我问的原因是 ViewData["Description_Current"]的类型为 Object,签名 Html.TextArea(String, Object)的重载-尽管此例中的对象表示html属性。这就是为什么编译器在将html属性添加为第三个参数之前不会提示的原因-在此之前,第二个参数允许为 Object,但是一旦添加第三个参数,第二个参数就必须为 String

关于.net - MVC Html.TextArea 过载问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/955999/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com