Iran58
پنج شنبه 11 مرداد 1397, 14:17 عصر
سلام
چگونه می توانم بکمک ajax وقتی روی دکمه مورد نظر در view کلیک کردم داخل div مورد نظرم PartialView را نمایش بدهم
چه کدهای باید بنویسم
کدهای که نوشته ام هیچکدام کار نکرده است
باتشکر
میلاد رئیسی
دوشنبه 15 مرداد 1397, 10:16 صبح
با سلام و احترام .
شما میبایست یک اکشن متد مانند زیر در کنترلر خودتون بنویسید :
public ActionResult Create()
{
var model = new MyModel();
if (Request.IsAjaxRequest())
{
return PartialView( "_Partial", model.PartialModel );
}
else
{
return View( model );
}
}
و در ویو مورد نظر کد های زیر رو بنویسید :
$(function(){
$(document).ajaxStart(function () {
//show a progress modal of your choosing
showProgressModal('loading');
});
$(document).ajaxStop(function () {
//hide it
hideProgressModal();
});
$.ajax({
url: '/controller/create',
dataType: 'html',
success: function(data) {
$('#myPartialContainer').html(data);
}
});
});
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.