Question: Set text inside @html.Textareafor

Question

Set text inside @html.Textareafor

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

I am using asp.net 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>
@using(Html.BeginForm("EditQuote","Home"))
{
    <p>
        <label>Your Quote</label>
        @Html.TextAreaFor(d=>d.quotes, new { @Value = @TempData["quote"]})
        @Html.ValidationMessageFor(d => d.quotes)
    </p>
    <input type="submit" name="submit" value="Edit my quote!"/>
}
Answers
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:

@Html.TextAreaFor(model=>model.quotes)
Source Show
◀ Wstecz