致电控制器
action: @Url.Action( "UploadFiles", "Dokument", new { } )
使用startTabIndex
public JsonResult UploadFiles()
{
var foo = 0;
return Json(new { startTabIndex = foo });
}
如何访问startTabIndex
属性?
complete: function (ajaxContext) {
console.log('ajaxContext: ' + ajaxContext); // not undefined
console.log(ajaxContext.startTabIndex); // undefined
startTabIndex = ajaxContext.startTabIndex; // not working
}
答案 0 :(得分:2)
您可以尝试将此逻辑放在一个单独的javascript文件中,该文件可以从您的视图中引用。例如,您可以将URL存储到视图中的全局javascript变量中:
<script type="text/javascript">
var uploadFileUrl = '@Url.Action("UploadFiles", "FileController")';
</script>
<script type="text/javascript" src="~/scripts/myscript.js"></script>
并在脚本内部进行AJAX调用:
$.ajax({
type: "GET",
dataType: "json",
url: uploadFileUrl,
success: function(data) {
console.log(data);
}
});
您正在调用的控制器操作返回JsonResult:
public ActionResult UploadFiles()
{
var foo = 0;
var model = new
{
startTabIndex = foo
};
return Json(model, JsonRequestBehavior.AllowGet);
}