简体   繁体   English

为什么我的“提交”按钮不提交表单?

[英]Why doesn't my submit button submit the form?

My form isn't always submitted when I hit the submit button. 当我点击“提交”按钮时,我的表格并不总是提交。

On my form I have one submit button. 在我的表单上,我有一个提交按钮。 When I first hit the button, the form will submit. 当我第一次点击按钮时,表单将提交。 But when there's a validation error, the error is shown. 但是,当出现验证错误时,会显示该错误。 But when I fix that error and press the submit button again, the form is not submitted. 但是,当我修复该错误并再次按下“提交”按钮时,该表单未提交。 This will happen if you work with 'normal' speed; 如果您以“正常”速度工作,就会发生这种情况。 if you do everything very slow, then the form will submit. 如果您做的一切都很慢,那么表单将提交。

In the 'normal speed' mode I see in FireBug that there's a request to the server, but my breakpoint in the code is never hit! 在“正常速度”模式下,我在FireBug中看到对服务器的请求,但是我的代码中的断点从未被击中! So I keep on the same page and nothing happens. 所以我保持在同一页面上,没有任何反应。 When I click multiple times (5-10) or I wait a few seconds and then click the submit button, the submit will reach my code. 当我单击多次(5-10)或等待几秒钟然后单击“提交”按钮时,提交将到达我的代码。

I am using MVC4 with the .NET 4.5 framework. 我将MVC4与.NET 4.5框架一起使用。

I hope someone can help me with this.. 我希望有人可以帮助我。

EDIT: 编辑:

This is the code I am talking about. 这是我正在谈论的代码。

My html (with razor) code: 我的HTML(带有剃须刀)代码:

<div id="content" class="boxBorder">
    <form method="post" action="/Import/ProcessStep" @(Model.UploadFiles ? "enctype=multipart/form-data" : "") id="wizardForm">
        <table id="detailsTable" width="550" cellspacing="0" border="0">
            <thead>
                <tr>
                    <th class="first">Importwizard
                    </th>
                </tr>
                <tr>
                    <th></th>
                </tr>
            </thead>
            <tfoot>
                <tr>
                    <td></td>
                </tr>
            </tfoot>
            <tbody>
                <tr>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td>
                        <div id="ImportProgressBar">
                            <ul>
                                @foreach (var step in Model.StepNames)
                                { 
                                    <li>
                                        <div class="WizardProgressStep">
                                            <img src="@step.Value" class="ProgressStepImage" />
                                            <br />
                                            <span>@step.Key</span>
                                        </div>
                                    </li>
                                }
                            </ul>
                        </div>
                        <div id="StepTitle">
                            @Model.StepTitle
                            <hr />
                        </div>
                        <div id="StepContent">
                            @RenderBody()
                        </div>
                    </td>
                </tr>
                <tr>
                    <td>&nbsp;</td>
                </tr>
                <tr>
                    <td>
                        <div id="WizardNavigationBox">
                            @if (Model.HasPreviousButton)
                            {
                                <input type="submit" name="PreviousStep" id="PreviousStep" value="Vorige" class="button icon add" />
                            }

                            @if (Model.HasNextButton)
                            {
                                <input type="submit" name="NextStep" id="NextStep" value="Volgende" class="button icon add saveButton" />
                            }
                        </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </form>
</div>

My controller: 我的控制器:

    [HttpPost]
    public ActionResult ProcessStep(FormCollection formCollection)
    {
        WebMediator mediator = new WebMediator();

        ViewResult newStep;
        GenericWizardViewModel viewModel;

        if (formCollection["NextStep"] != null)
        {
            ValidateStep(formCollection);
            if (ModelState.IsValid)
            {
                mediator.ProcessStep(formCollection);

                newStep = mediator.GetNextStep();
            }
            else
            {
                IWizardStep currentStep = mediator.GetCurrentStep();
                viewModel = mediator.CreateViewModel(currentStep);

                return this.RazorView(currentStep.StepName, viewModel);
            }
        }
        else
        {
            newStep = mediator.GetPreviousStep();
        }

        viewModel = newStep.Model as GenericWizardViewModel;

        return this.RazorView(newStep.ViewName, viewModel);
    }

We finally figured it out. 我们终于弄清楚了。

All our controllers inherit from a custom BaseController class. 我们所有的控制器都继承自自定义BaseController类。 This BaseController had an trribute with OutputCache on it with a duration set to 10 seconds. BaseController有一个带有OutputCache的trtrute,持续时间设置为10秒。 Removing this attribute fixed my problem. 删除此属性解决了我的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM