1

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" } })
5
  • 1
    Where is the code that you use for TextArea()? And what does 99% of this code have to do with your question? Commented Apr 26, 2016 at 8:24
  • That's the code for EditorFor() You question is about TextArea() - what code did you try that gave that error? Commented Apr 26, 2016 at 8:28
  • Html.EditorFor(model => model.ProductFeatureName, new { htmlAttributes = new { class = "form-control" } }) Html.EditorFor(model => model.ProductFeatureValue, new { htmlAttributes = new { class = "form-control" } }) I want to use Html.TextArea instead of Html.EditorFor. Cannot i ? Commented Apr 26, 2016 at 8:30
  • Of course you can. Edit you code with the code you tried and we will correct it for you Commented Apr 26, 2016 at 8:31
  • i did try like this "Html.TextArea(model => model.ProductFeatureName, new { htmlAttributes = new { class = "form-control" } })" but red line appeared it's below and this error "cannot convert lambda expression to type 'string' because it is not a delegate type". Commented Apr 26, 2016 at 8:33

1 Answer 1

6

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>

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.