0

我创建了一个视图。在那里,我为“创建”和“取消”放置了 2 个多提交按钮。

现在,在取消单击时,将调用客户端验证。但我不想调用客户端验证。

我写了如下代码,请检查。我不希望在单击取消按钮时执行验证。

@model Blog.Models.User
@{
    ViewBag.Title = "Register New User";
}

@using Microsoft.Web.Mvc;
@using MVC3MultiSubmitButtonExtension;
<h2>
    Register New User</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>Fill User Details</legend>
        <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.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.Password)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Password)
            @Html.ValidationMessageFor(model => model.Password)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.EmailAddress)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.EmailAddress)
            @Html.ValidationMessageFor(model => model.EmailAddress)
        </div>
        <div class="editor-label">
            @Html.LabelFor(model => model.MobileNumber)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.MobileNumber)
            @Html.ValidationMessageFor(model => model.MobileNumber)
        </div>
        <p>
            @*  <input type="submit" value="Create" />*@
           @Html.MultiSubmitButton(Url.Action("Create"), "btnCreate", "Create")
           @Html.MultiSubmitButton(Url.Action("Cancel"), "btnCancel", "Cancel")
        </p>
    </fieldset>
}
<div>
    @Html.ActionLink("Click here to go Login Page", "Index")
</div>
4

1 回答 1

0

如果您分配class="cancel"给您的取消提交按钮,客户端验证将不会运行。我无法告诉您分配此类的方式,因为您似乎正在使用一些Html.MultiSubmitButton不属于 ASP.NET MVC 的自定义帮助程序。所以你必须检查它的文档。

于 2012-06-22T06:58:13.037 回答