所需的流程:
问题:保存表单时调用了两个HttpPost操作。
目前的代码: 初始表格
@using (Html.BeginForm())
{
@Html.AntiForgeryToken();
...
var groupItem = settings.Items.AddGroupItem(grpSet =>
{
grpSet.ShowCaption = DefaultBoolean.False;
grpSet.GroupBoxDecoration = GroupBoxDecoration.None;
grpSet.SettingsItemCaptions.Location = LayoutItemCaptionLocation.Left;
grpSet.SettingsItemHelpTexts.Position = HelpTextPosition.Auto;
grpSet.ColCount = 2;
});
groupItem.Items.Add(item =>
{
item.NestedExtensionType = FormLayoutNestedExtensionItemType.Button;
item.ShowCaption = DefaultBoolean.False;
item.ColSpan = 1;
item.HorizontalAlign = FormLayoutHorizontalAlign.Center;
var btnSettings = (ButtonSettings)item.NestedExtensionSettings;
btnSettings.Name = "btnCreate";
btnSettings.Text = "Finish and save";
btnSettings.UseSubmitBehavior = true;
btnSettings.RouteValues = new { Controller = "General", Action = "A_General", completed = true };
});
}
弹出窗口的结果视图:
<div> Display result
@Html.DevExpress().HyperLink(hl =>
{
hl.Name = "createAP" ;
hl.NavigateUrl = "javascript:void(0)";
hl.Properties.ClientSideEvents.Click = "function (s, e) { pcCreateAP.PerformCallback(); pcCreateAP.Show(); }";
hl.Properties.ImageUrl = "~/Images/AddFile_16x16.png";
hl.Attributes.Add("title", "Create AP");
}).GetHtml()
</div>
@Html.DevExpress().PopupControl(settings =>
{
settings.Name = "pcCreateAP";
settings.Width = 700;
settings.AllowResize = true;
settings.AllowDragging = true;
settings.CloseAction = CloseAction.CloseButton;
settings.CloseOnEscape = true;
settings.PopupAnimationType = AnimationType.Fade;
settings.HeaderText = "Create Health Action Plan";
settings.Modal = true;
settings.PopupHorizontalAlign = PopupHorizontalAlign.WindowCenter;
settings.PopupVerticalAlign = PopupVerticalAlign.TopSides;
settings.SetContent(() =>
{
Html.Action("CreateAP", "AP", null);
});
}).GetHtml()
弹出窗口的cshtml也包含
Html.DevExpress().Button(btnSet =>
{
btnSet.Name = "btnCreateAp";
btnSet.ControlStyle.CssClass = "button";
btnSet.Width = Unit.Percentage(100);
btnSet.RouteValues = new { Controller = "AP", Action = "CreateAP" };
btnSet.Text = "Create";
btnSet.UseSubmitBehavior = true;
}).GetHtml();
这两个动作都得到了[HttpPost,ValidateAntiForgeryToken]装饰。 我不知道它是DevExpress问题还是一些基本的HTML ......
答案 0 :(得分:0)
您应该尝试在代码的第一行显式指定Controller和Action Method。
@using (Html.BeginForm())
替换为
@using (Html.BeginForm("YourAction", "YourController", FormMethod.Post))
{
}
答案 1 :(得分:0)
解决方案是使用与控制器中的get函数不同的名称。在我的情况下,我刚刚将它重命名为CreateAPSave,现在保存初始表单时不会调用它。