Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<textarea> doesn't show inner text when together with "asp-for="

This shows "Hello there" inside the textarea:

@model PlannerViewModel
@{
    ViewData["Title"] = "Test";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Test</h2>
<form method="post">
    <div class="border rounded">
        <textarea class="form-control MyTextArea" rows="4">Hello there</textarea>
    </div>
</form>

This doesn't show "Hello there" inside the text area:

@model PlannerViewModel
@{
    ViewData["Title"] = "Test";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Test</h2>
<form method="post">
    <div class="border rounded">
        <textarea class="form-control MyTextArea" rows="4" asp-for="EditShutdown.Comments_Operations">Hello there</textarea>
    </div>
</form>

As you see, the only difference is the presence of "asp-for". Am I doing something wrong? Is there any workaround?

like image 459
Conto Avatar asked Dec 30 '25 18:12

Conto


1 Answers

To solve this annoying event, you can use ;

@Html.IdFor

and

@Html.NameFor

Example;

<textarea id="@Html.IdFor(m => m.EditShutdown.Comments_Operations)" name="@Html.NameFor(m => m.EditShutdown.Comments_Operations)">Hello there</textarea>
like image 125
Sreilus Avatar answered Jan 05 '26 00:01

Sreilus



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!