【发布时间】:2014-12-26 11:59:22
【问题描述】:
我通过 Ajax 调用局部视图,但它给出的结果未定义。
我的控制器是:
[HttpGet]
public ActionResult CallPartial()
{
if (Request.IsAjaxRequest())
{
return PartialView("~/Views/Partial1");
}
else
{
return View();
}
}
我的看法是:
<div id="divpartial">hello
<button id="btn" onclick="callpartial()">Click</button>
</div>
<script type="text/javascript" >
$(function callpartial() {
$.ajax({
url: '~/Controllers/Home/CallPartial',
contentType: 'application/html; charset=utf-8',
type: 'Get',
dataType: 'html',
success: function (status) {$("#divpartial").html("Welcome to partial view"); },
error: function (status) {
alert(status.Value);
}
alert("Request Fails");
});
});
最后我的部分观点是:
<body>
<div>hello this partial</div>
</body>
【问题讨论】:
标签: jquery html ajax model-view-controller partial-views