我有一个jquery点击方法,看起来像这样
<script type="text/javascript">
function clickView(e) {
e.preventDefault();
var dataItem = this.dataItem($(e.currentTarget).closest("tr"));
$.ajax({
url: "/Jac/ViewCustomDetails",
data: { productId: dataItem.Id },
success: function (response) {
$("#details").html(response);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
document.write(xhr.responseText);
}
});
}
</script>
基本上,这会对我的控制器进行AJAX调用以呈现操作。
行动ViewCustomDetails
,位于JacController
内,并且在某个区域内如下所示:
public ActionResult ViewCustomDetails(int productId)
{
Detail model;
model = new Detail
{
Price = productId.ToString(),
Origin = productId.ToString()
};
return View(model);
}
当我点击我的按钮以激活AJAX呼叫时,我能够突破我的行动。但是我在视图中看到了这个错误
The view 'ViewCustomDetails' or its master was not found or no view engine supports the searched locations. The following locations were searched:
~/Views/Jac/ViewCustomDetails.aspx
~/Views/Jac/ViewCustomDetails.ascx
~/Views/Shared/ViewCustomDetails.aspx
~/Views/Shared/ViewCustomDetails.ascx
~/Views/Jac/ViewCustomDetails.cshtml
~/Views/Jac/ViewCustomDetails.vbhtml
~/Views/Shared/ViewCustomDetails.cshtml
~/Views/Shared/ViewCustomDetails.vbhtml
显然,我的视图文件夹中没有这样的控制器/动作,因为我的控制器在一个区域内。
如何让它引用我所在地区的控制器?
答案 0 :(得分:0)
它正在引用您的控制器,但ViewCustomDetails方法中的行return View(model);
需要存在一个View文件,通常称为ViewCustomDetails.cshtml
此View文件必须采用Detail
您可能还需要JSONify返回视图。
答案 1 :(得分:0)
我只需要在jquery代码中将区域名称添加到我的URL中
url: "/Dan/Jac/ViewCustomDetails",
而不仅仅是
url: "/Jac/ViewCustomDetails",