Erdem Nayir
Erdem Nayir

Reputation: 85

Using of @Html.TextArea in asp.net mvc

I want to use @Html.TextArea() instead of @Html.EditorFor() but I am getting this error

cannot convert lambda expression to type 'string' because it is not a delegate type.

Model

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; }

    ....
}

View

// 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" } })

Upvotes: 1

Views: 3819

Answers (1)

user3559349
user3559349

Reputation:

If you use an expression, then you need to use the strong typed xxxFor() methods

@Html.TextAreaFor(m => m.ProductFeatureValue, new { @class = "form-control" })

alternatively your can use

@Html.TextArea("ProductFeatureValue", new { @class = "form-control" } )

or you could add the DataTypeAttribute to you property

[DataType(DataType.MultilineText)]
public string ProductFeatureName { get; set; }

and use EditorFor() which will then generate a <textarea>

Upvotes: 6

Related Questions