Question: Set text inside @html.Textareafor


Set text inside @html.Textareafor

Answers 2
Added at 2017-01-05 01:01

I am using core razor engine. I am trying to set text inside of my text area. I looked on stack and followed previous answers, but nothing seems to be working. Here is my code

<h1>@TempData["quote"]</h1>// this prints out the correct value
@model login.Models.Quotes
<h1>Edit Your Quote</h1>
        <label>Your Quote</label>
        @Html.TextAreaFor(d=>d.quotes, new { @Value = @TempData["quote"]})
        @Html.ValidationMessageFor(d => d.quotes)
    <input type="submit" name="submit" value="Edit my quote!"/>
nr: #1 dodano: 2017-01-05 01:01

Seems like maybe your lamda expression is not being evaluated properly. Try:

  @Html.TextAreaFor(d => d.quotes, new { @Value = @TempData["quote"]})
nr: #2 dodano: 2017-01-05 05:01

You don't use attributes to set the value in the view - you set the value in the controller through the model property and bind that property to the text box.

In your controller:

model.quotes = TempData["quote"];

In your view:

Source Show
◀ Wstecz