[英]Is there a way to clear an @Html.TextAreaFor
我正在使用asp.net核心剃刀引擎。 在TextArea中輸入文本並單擊“提交”按鈕后,我想清除TexArea中的文本。 我無法找到有關如何使用html或c#進行此操作的任何信息。 這是我的TextAreaFor代碼
<h1>Add Your Comment</h1>
@using(Html.BeginForm("AddComment","Home"))
{
<p>
<label>Your Comment</label>
@Html.TextAreaFor(d=>d.comment)
@Html.ValidationMessageFor(d => d.comment)
</p>
<input type="submit" name="submit" value="Add my Comment!"/>
}
這是我的AddComment控制器
[HttpPost]
[Route("addComment")]
public IActionResult AddComment(Messages model)
{
var user_id = HttpContext.Session.GetString("Id");
if(user_id == null){
return RedirectToAction("Index");
}
model.Users_id = Convert.ToInt32(user_id.ToString());
userFactory.addComment(model, user_id);
setTempData();
ViewBag.Messages = userFactory.FindAll();
model.comment ="";
return View("Login", model);
}
對userFactory的調用工作正常,這是對與我的數據庫對話的我的工廠的調用
完成所有工作后,您不應return View(...)
,而應使用RedirectToAction
將用戶重定向到該return View(...)
。 這樣,您可以清除所有表單字段,並使用Post-redirect-get模式 ,這將阻止您的用戶重復提交。
發布整個頁面時,幾乎應始終應用相同的模式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.