0

I am attempting to implement an Update on a current text area value.

The datatype is set for multiline in my model

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

When the page loads for the textarea, it does not populate.

@Html.TextAreaFor(a => a.Text, new { @Value = Model.Text })

But for a textbox it does populate

@Html.TextBoxFor(a => a.Text, new { @Value = Model.Text })

Is there something I'm missing? this seems pretty straight forward.

it should work like this

enter image description here

walangala
  • 231
  • 1
  • 4
  • 15
  • 1
    edited so I don't get yelled at – walangala Mar 22 '18 at 19:40
  • 1
    https://stackoverflow.com/questions/8723028/replacement-for-textareafor-code-in-asp-net-mvc-razor?rq=1 – Hussein Salman Mar 22 '18 at 19:45
  • no, that is not what I'm looking for, the Model.Text value needs to populate inside the textbox – walangala Mar 22 '18 at 19:47
  • @Html.TextAreaFor(a => a.Text) should be enough - MVC takes care of populate value for textarea – Jakub Jarzabek Mar 22 '18 at 20:21
  • Never ever set the `value` attribute when using a `HtmlHelper` method. And a ` –  Mar 22 '18 at 23:52

2 Answers2

0
@Html.TextAreaFor(a => a.Text,  new { id = "SomeID", placeholder = "Text", Value = Model.Text})
Dylan Wright
  • 1,118
  • 12
  • 19
  • Value should already be populated in the text area as if it was a placeholder, a user would be able to edit what is in the text area – walangala Mar 22 '18 at 19:56
  • Was taking a shot in the dark. Really would need to see more code. Definitely is helpful – Dylan Wright Mar 22 '18 at 20:03
0

@Html.TextAreaFor(m => m.UserName) should be enough - ASP MVC takes care of populate current value from model to textarea. Using { @Value = Model.Text } doesn't apply to textarea as it does not uses value attribute: How to add default value for html <textarea>?