Asp.net mvc 3 如果禁用提交按钮,则不会激发HttpPost方法

Asp.net mvc 3 如果禁用提交按钮,则不会激发HttpPost方法,asp.net-mvc-3,Asp.net Mvc 3,我的视图如下:DemoView.cshtml @model Mvc3Razor.Models.UserModel @{ ViewBag.Title = "Create"; Layout = "~/Views/Shared/_Layout.cshtml"; } <h2> Create</h2> <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/ja

我的视图如下:DemoView.cshtml

@model Mvc3Razor.Models.UserModel
@{
    ViewBag.Title = "Create";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>
    Create</h2>
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>UserModel</legend>
        <div class="editor-label">
            @Html.LabelFor(model => model.UserName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.UserName)
            @Html.ValidationMessageFor(model => model.UserName)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.FirstName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.FirstName)
            @Html.ValidationMessageFor(model => model.FirstName)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.LastName)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.LastName)
            @Html.ValidationMessageFor(model => model.LastName)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.City)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.City)
            @Html.ValidationMessageFor(model => model.City)
        </div>
        <p>
            <input type="submit" value="Create" /></p>
    </fieldset>
}
<div>
    @Html.ActionLink("Back to List", "Index")
</div>
<script type="text/javascript">
    $(function () {
        $('input[type="submit"]').click(function () {
            $(this).attr('disabled', 'disabled');
        });
    });
</script>
为了防止多次单击按钮,我尝试在用户单击Create按钮后禁用按钮,但一旦禁用Create按钮,则不会触发HttpPost方法


有人能帮我解决这个问题吗?

尝试在提交表单时禁用按钮,而不是在单击提交按钮时禁用按钮:

$("form").submit(function() {
    $(this).attr("disabled", "disabled");
    return true;
});

尝试在提交表单时禁用该按钮,而不是在单击“提交”按钮时禁用该按钮:

$("form").submit(function() {
    $(this).attr("disabled", "disabled");
    return true;
});

我建议在成功发布后将用户重定向回索引页面。你想用吗

其中“有助于避免 重复表单提交,并允许web应用程序表现得更好 直观地使用浏览器书签和“重新加载”按钮“


有关更多详细信息,请参阅此部分。

我建议在成功发布后将用户重定向回索引页。你想用吗

其中“有助于避免 重复表单提交,并允许web应用程序表现得更好 直观地使用浏览器书签和“重新加载”按钮“

有关更多详细信息,请参见此

usrs.Create(um);
//Redirect to Index Page here