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);
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);
});
创建一个动作并使用json返回字符串中的部分视图,然后使用
$(".div_class_name").html(result);
$('#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.
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.