Pavan
Pavan

Reputation: 1083

Rendering partial pages in asp.net MVC3

I just started working on ASP .NET MVC3 project. I want to render a partial view (*.cshtml file) within javascript/AJAX and put it in a division, Can anybody help me with sample code for that. Thanks in advance.

I tried this way, but not working.

var result = '<%= Html.RenderPartial("_Partialview"); %>';
$(".div_class_name").html(result);

Upvotes: 0

Views: 591

Answers (3)

arnoldrob
arnoldrob

Reputation: 833

$('#trigger').click(function () {
$.ajax({
  url: '@Url.Action("Method", "Controller")', 
  success: function(data){
    $('#targetDIV').html(data);
  }
    });
    });

So when you will click for example on a trigger button this ajax call will be executed and the partial view returned will be placed to your targetDIV.

Upvotes: 0

Amit
Amit

Reputation: 15387

create a action and return partial view in string with json and then use

$(".div_class_name").html(result);

Upvotes: 0

Deniz Traka
Deniz Traka

Reputation: 84

Create a method that returns partial view in Controller class, than call that method with ajax get.

$.get('controller/getpartial', function(data) {

  $('.div_class_name').html(data);


});

Upvotes: 1

Related Questions