当我尝试使用NewForm.aspx保存项目时,我正在尝试重定向到“显示表单”而不是返回“所有项目”视图。我能够完成重定向,但它没有保存该项目。我的代码如下所示,并输入NewForm.aspx页面上的脚本编辑器Web部件:
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>
// JavaScript source code
$(document).ready(function() {
var button = $("input[id$=SaveItem]");
// change redirection behavior
button.removeAttr("onclick");
button.click(function() {
var elementName = $(this).attr("name");
var aspForm = $("form[id=aspnetForm]");
var oldPostbackUrl = aspForm.attr("action");
//var oldPostbackUrl = aspForm.action;
var currentSourceValue = GetUrlKeyValue("Source", true, oldPostbackUrl);
var newPostbackUrl = oldPostbackUrl.replace(currentSourceValue, "/sites/mysite/DispForm.aspx");
if (!PreSaveItem()) return false;
WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(elementName, "", true, "", newPostbackUrl, false, true));
});
});
</script>