ASP.NET MVC - Ajaxified RenderAction

I am pleased with what the RenderAction () function does. However, I would like to ajaxify load and store data in a partially processed action, so that everything happens on one page.

Imagine the following case: I have an idea of ​​the details of the article, where there is a link "Add a comment" below the contents of the article. When he clicks, a comment form will appear below the contents of the message. The user should be able to fill out the comment field and send data without updating the entire view, only partially processed action. Also, the view should contain several comments to be added to one session (several AJAX calls for RenderAction ());

What is the best way to achieve this?

+6
ajax asp.net-mvc renderaction
source share
1 answer

Act:

[HttpGet] public ActionResult AddComment() { return PartialView(); // presumes partial view is called "AddComment" and needs no model // you know what to do otherwise. } 

View:

 <input type="button" value="Add Comment" onclick="addComment()" /> 

JavaScript:

 function addComment() { $("#comments").append("<div></div>").load("/ControllerName/AddComment"); } 

These are the basics. You can make it difficult as you like.

+13
source share

All Articles