简体   繁体   中英

Display comment without refreshing the view Asp.Net Core 3.1?

Is This Possible Without 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:

 [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. Display the comment blocks as a partial view. Use Ajax to send the backend request and update the partial view.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM