I have two submit buttons on a page using MVC 3 with client-side validation. There's a text box that is mapped to an object that has data annotations that make it required. As long as I'm trying to click the Save button it works fine. It ensures that the textbox is filled-in.
我在一个页面上有两个提交按钮,使用MVC 3进行客户端验证。有一个文本框映射到一个对象,该对象具有使其必需的数据注释。只要我试着点击Save按钮,它就能正常工作。它确保文本框被填入。
However, when I try to click the Delete button to go back to the controller and bypass the client-side validation it of course only works if the textbox is filled in. I see this need for situations where there is a Cancel button as well.
但是,当我尝试单击Delete按钮返回控制器并绕过客户端验证时,当然只有在填充了文本框之后,它才会工作。我看到在有取消按钮的情况下也需要这样做。
I'm unable to find any examples on how to have a submit button that still posts back to the controller but also allow one of the submit buttons to not validate the page.
我无法找到任何关于如何有一个提交按钮的例子,该按钮仍然可以返回到控制器,但也允许提交按钮中的一个不能验证页面。
Here's the markup:
这里的标记:
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<% using (Html.BeginForm())
{
%>
<fieldset>
<br />
<div class="grid_10">
<div class="grid_2 fieldlabel alpha">
<%= Html.LabelFor(model => model.Name) %>
</div>
<div class="grid_8 omega" style="white-space: nowrap;">
<%= Html.TextBoxFor(model => model.Name, new { @class = "focus textbox_300" }).MaxLength(100)%>
<%= Html.ValidationMessageFor(model => model.Name) %>
</div>
<div class="clear">
</div>
<br />
</div>
<div class="clear">
</div>
<div class="grid_4 prefix_2">
<input type="submit" value="Save" id="btnSave" name="btnSubmit" style="width:60px;" />
<input type="submit" value="Delete" id="btnDelete" name="btnSubmit" style="width:60px;" />
</div>
<div class="clear">
</div>
<br />
</fieldset>
<% } %>
1 个解决方案
#1
1
Are they posting to the same ActionMethod?
他们发的是同一个ActionMethod吗?
You could put it into it's own <form>
你可以把它放到它自己的
#1
1
Are they posting to the same ActionMethod?
他们发的是同一个ActionMethod吗?
You could put it into it's own <form>
你可以把它放到它自己的