我想在我的剃须刀网页(不是 mvc)中使用两个 froms,我的问题是使用多个表单我如何对我的项目说单击了哪个表单按钮,另一个问题是验证,因为在 web 表单项目中我是使用验证组来分隔验证,但在这里我不知道如何在客户端验证和服务器端验证中处理它这是我的代码:
@{
Page.Title = "";
Layout = "~/_layout.cshtml";
Validation.Add("txt1", Validator.Required("can not leave empty"));
Validation.Add("txt2", Validator.Required("can not leave empty"));
if (IsPost)
{
if (!Validation.IsValid())
{
Validation.AddFormError("there are errors");
}
}
}
<style>
.validation-summary-errors {
border: 2px solid #990099;
color: red;
}
.field-validation-error {
color: Red;
}
.input-validation-error {
color: #990099;
background-color: #ff80ff;
border-top: 2px solid #990099;
border-left: 2px solid #990099;
}
</style>
<div>
<script src="~/jquery-1.7.2.min.js"></script>
<script src="~/jquery.validate.min.js"></script>
<script src="~/jquery.validate.unobtrusive.min.js"></script>
</div>
<p style="height:10px;"></p>
<div>
<form name="f1" action="/" method="post">
<div>
<input name="txt1" type="text"
class="@Validation.ClassFor("txt1")"
/>
@Html.ValidationMessage("txt1")
</div>
<div>
<input type="submit" name="s1" value="Send 1" />
</div>
</form>
</div>
<br />
<form name="f2" action="/" method="post">
<div>
<input name="txt2" type="text"
class="@Validation.ClassFor("txt2")"
/>
@Html.ValidationMessage("txt2")
</div>
<div>
<input type="submit" name="s2" value="Send 2" />
</div>
</form>