我想使用@Html.TextArea()
代替@Html.EditorFor()
,但我收到此错误
无法将lambda表达式转换为'string'类型,因为它不是委托类型。
模型
public class ProductFeature
{
[Required(ErrorMessage = "{0} boş geçilemez")]
[DisplayName("Ürün Özellik Adı")]
public string ProductFeatureName { get; set; }
[Required(ErrorMessage = "{0} boş geçilemez")]
[DisplayName("Ürün Özellik Değeri")]
public string ProductFeatureValue { get; set; }
....
}
查看
// Works
@Html.EditorFor(model => model.ProductFeatureName, new { htmlAttributes = new { @class = "form-control" } })
// Throws error
@Html.TextArea(model => model.ProductFeatureName, new { htmlAttributes = new { @class = "form-control" } })
答案 0 :(得分:5)
如果您使用表达式,则需要使用强类型xxxFor()
方法
@Html.TextAreaFor(m => m.ProductFeatureValue, new { @class = "form-control" })
或者你可以使用
@Html.TextArea("ProductFeatureValue", new { @class = "form-control" } )
或者您可以将DataTypeAttribute
添加到您的媒体资源
[DataType(DataType.MultilineText)]
public string ProductFeatureName { get; set; }
并使用EditorFor()
,然后生成<textarea>