skip to Main Content

Ok, so basically i have an form which edits data in my database. I have the following inputs:

   <input value="@title" type="text" asp-for="@Model.ProjName" class="form-control" placeholder="Ticket1" />
   <textarea  value="@description" type="text" asp-for="@Model.ProjDescription" class="form-control" rows="3"></textarea>

I can pre-populate the input just fine, however value doesn’t work on the textarea. What is the correct way of populating it?

2

Answers


  1. This will solve your problem. Text area acts differently from input tag . So instead of using value parameter, add your value between open and close tag of text area

     <textarea  type="text" asp-for="@Model.ProjDescription" class="form-control" rows="3">@Model.description</textarea>
    

    Here is a .net fiddle with an example
    https://dotnetfiddle.net/2TYEOk

    Login or Signup to reply.
  2. Since you use asp-for="@Model.ProjDescription",so the default value will be @Model.ProjDescription,if you want to bind value with @description,you can try to use id and name to replace asp-for="@Model.ProjDescription".Here is the sample code:

    <textarea type="text" id="ProjDescription" name="ProjDescription" class="form-control" rows="3" >@description</textarea>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search