0
votes

I have a razor-pages button tag-helper calling a asp-page-handler that has an asp-route-content parameter that needs to gets it's value from a textarea control within the razor page view on button submit. How can this be accomplished?

Razor view partial code:

 <form method="post">
      <div class="modal-body">
           <textarea id="content" name="content" cols="90" rows="4" placeholder="Comment" required></textarea>
      </div>
      <div class="modal-footer">
           <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
           <button type="submit" asp-page="/Post" asp-page-handler="ReplyToComment"
                   asp-route-blogid="@Model.BlogID" asp-route-parentid="@Model.ID"
                   asp-route-email="@user.Email" asp-route-author="@author"
                   asp-route-content="" class="btn btn-primary">Save Reply</button>
      </div>
 </form>

Razor page handler :

    public async Task<IActionResult> OnPostReplyToComment(int blogid, 
           int parentid, string email, string author, string content)
1

1 Answers

0
votes

You need to either bind the textarea content to a Property on your page:

    [BindProperty]
    public string Content { get; set; }

and use the asp-for tag-helper on the textarea:

<textarea asp-for="Content" cols="90" rows="4" placeholder="Comment" required></textarea>

Or use the [FromForm] attribute in the method signature:

public async Task<IActionResult> OnPostReplyToComment(int blogid, 
       int parentid, string email, string author, [FromForm] string content)

For more information see MS Docs on Model Binding