Maztt - Asp
Maztt - Asp
maztt
THURSDAY, 14 APRIL 2011 There was an error in this gadget
I will going to demonstrate how we can render PartialViews using Jquery Ajax. I will I am working mainly on .net technologies and is very
be clicking an a href link ,then I will be calling the controller through jquery Ajax passionate about learning and implementing new things.
which will fill the partialview for a really nice user experience.
View my complete profile
Step 1:
LABELS
First of all we will be creating an DisplayData class for the use for this example in
the model. Asp.net mvc (12)
? Asp.net mvc Jquery (1)
1 public class DisplayData automapper (1)
2{ c# (2)
3 public int ID { get; set; } datannotations (2)
4 public DisplayData(int ID) Dotnetnuke (1)
5 {
entity framework (2)
6 this.ID = ID;
Json (2)
7 }
8} Linq (3)
voice actions android (1)
We will create a Clicks page and write the following code on it. Specially note 2012 (12)
empty here which will going to empty and then fill partialview with new records. 2011 (12)
? December (1)
1 $(document).ready(function () {
November (1)
2 $('.msg').click(function () {
3 var id = this.id; June (1)
4 $.ajax({ May (1)
5 url: "/Category/Display", April (2)
6 data: { data: id },
Asp.net mvc razor render partial view using
7 success: function (mydata) { jquery...
8 $("#link").empty().append(mydata);
Google voice actions for android
9 },
10 type: "POST" March (2)
11 });
February (4)
12 return false;
13 });
14 });
15
16
17 <a class="msg" href="#" id="1">Click Me</a>
18 <a class="msg" href="#" id="2">AND Click Me</a>
19 <div id="link">
20 </div>
Step 3:
Step 4:
And Finally Create an action methods inside the Category controller for calling the
view and then rendering the partialview.
?
1 public ActionResult Clicks()
2 {
3 return View();
4 }
http://mazharkaunain.blogspot.in/2011/04/aspnet-mvc-render-partial-view-using.html 1/3
8/9/2017 maztt: Asp.net mvc razor render partial view using jquery Ajax
5
6 public ActionResult Display(int data)
7 {
8 List<DisplayData> Display = new List<DisplayData>();
9 if (data == 1)
10 {
11 Display.Add(new DisplayData(3));
12 Display.Add(new DisplayData(4));
13 }
14 else
15 {
16 Display.Add(new DisplayData(1));
17 Display.Add(new DisplayData(2));
18 }
19
20 return PartialView("ClicksUC", Display);
21 }
13 comments:
Reply
nice. i was looking for such a simple solution instead of using jquery tempate or
knockout.js etc.
Reply
http://mazharkaunain.blogspot.in/2011/04/aspnet-mvc-render-partial-view-using.html 2/3
8/9/2017 maztt: Asp.net mvc razor render partial view using jquery Ajax
This... saved... my... bacon!
Thank you!
Reply
I have displayed the contents through ajax call in jquery but it is also showing
view's own content either. how to replace them ..
here is my Jquery code as well..
$("#render").click(function () {
alert("button Clikced");
$.ajax({
url: "AddStudentsPartial",
type: 'GET',
cache: false,
success: function (result) {
alert(result);
$('#partial').html(result);
}
});
});
Reply
Reply
Powered by Blogger.
http://mazharkaunain.blogspot.in/2011/04/aspnet-mvc-render-partial-view-using.html 3/3