我有一个Import.cshtml页面,它有2个jquery选项卡,如:
@model Models.BaseDataModel
@{
Layout = "~/Views/Shared/_Layout.cshtml";
var val = Json.Encode(Model);
}
<script>
$(document).ready(function () {
$("#tabs").tabs({
activate: function (event, ui) {
window.location.hash = ui.tab.hash;
}
});
});
</script>
<div class="row-fluid">
<div id="tabs">
<ul>
<li><a href="#import-container"><i class="icon-upload icon-large"></i> IMPORT</a></li>
<li>
<a href="#sanitize-container"><i class="icon-list icon-large"></i> SANITIZE</a>
<span class="badge badge-important">0</span>
</li>
</ul>
<div id="import-container">
@Html.Partial("_ImportData", Model)
</div>
<div id="sanitize-container">
</div>
</div>
</div>
然后在我的_ImportData局部视图中,我有一个函数,使用jquery点击按钮发布到我的控制器,如:
$('#btn-submit').click(function () {
var check = @Html.Raw(val)
$.ajax({
type: "POST",
url: '@Url.Action("ProcessAndSaveData", "ImportBaseData")',
data: JSON.stringify(check),
contentType: 'application/json; charset=utf-8',
async: true,
beforeSend: function () {
$('#spinner').show();
},
success: function (data) {
$('#spinner').hide();
alert(data.url);
if (data.url) {
window.location.href = data.url;
}
},
failure: function () {
}
});
});
然后我终于在我的控制器中:
[HttpPost]
public ActionResult ProcessAndSaveData(BaseDataModel model)
{
// Some code
return Json( new { url = Url.Action("Import", "ImportBaseData", new { area = "BaseData" }) + "#sanitize-container"});
}
但是这不会重定向到我在Import.cshtml视图中的Sanitize选项卡,我缺少什么或做错了什么?非常感谢任何帮助。