我是asp.net MVC的新手。当我清除此代码时,会显示错误。为什么要显示,我该如何解决?谢谢。
这是我的代码:
<% using (Html.BeginForm("DisplayCustomer","Customer",FormMethod.Post))
{ %>
Enter customer id :- <%= Html.TextArea("Id",Model)%> <br /> //shows error
<input type="submit" value="Submit customer data" />
<%} %>
错误讯息:
CS1973:'System.Web.Mvc.HtmlHelper'没有名为'TextArea'的适用方法,但似乎有一个名称的扩展方法。无法动态分派扩展方法。考虑转换动态参数或调用扩展方法而不使用扩展方法语法。
答案 0 :(得分:-1)
我认为问题在于您没有为TextArea方法提供正确的参数。您匹配的TextArea重载的第二个参数称为HtmlAttributes,它的类型为Object。它旨在获取您可能提供文本区域的html属性,例如id,class name,readonly或disabled。您正在为它提供一个模型,虽然该对象可能没有为文本区域提供html属性。
你应该像这样使用TextAreaFor
<%= Html.TextAreaFor(x=> x.id)%>
尝试在Mvc Forms上查找一些信息。它应该解释如何比我更好地使用它们。