我有一个razor-pages按钮标记帮助器,调用了一个asp-page-handler,该处理程序具有一个asp-route-content参数,需要从按钮提交时在razor页面视图中的textarea控件中获取其值。如何做到这一点?
剃刀视图部分代码:
<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>
剃刀页面处理程序:
public async Task<IActionResult> OnPostReplyToComment(int blogid,
int parentid, string email, string author, string content)
答案 0 :(得分:0)
您需要将textarea内容绑定到页面上的“属性”:
[BindProperty]
public string Content { get; set; }
并在文本区域上使用asp-for
标签帮助器:
<textarea asp-for="Content" cols="90" rows="4" placeholder="Comment" required></textarea>
或在方法签名中使用[FromForm]
属性:
public async Task<IActionResult> OnPostReplyToComment(int blogid,
int parentid, string email, string author, [FromForm] string content)
有关更多信息,请参见MS Docs on Model Binding