[英]Display comment without refreshing the view Asp.Net Core 3.1?
Is This Possible Without Ajax?如果没有 Ajax,这可能吗?
I Have a form for comments:我有一个评论表格:
<form asp-action="CommentUser">
<input type="hidden" name="videoid" value="@Model.Id" />
<div class="form-group">
<label class="control-label">Your Comment :</label>
<textarea name="comentuser" class="form-control">
</textarea>
</div>
Controller: Controller:
[HttpPost]
public IActionResult CommentUser(string comentuser,int videoid)
{
int iduser = _database.Users.FirstOrDefault(u => u.Email == User.Identity.Name).Id;
Comment comment = new Comment();
comment.TextComment = comentuser;
comment.VideoId = videoid;
comment.UserId = iduser;
_database.Comments.Add(comment);
_database.SaveChanges();
return Ok();
}
thanks谢谢
You would need to use ajax and partial views for the same.您需要使用 ajax 和部分视图。 Display the comment blocks as a partial view.
将注释块显示为局部视图。 Use Ajax to send the backend request and update the partial view.
使用 Ajax 发送后端请求并更新部分视图。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.