i wanted to use two froms in my razor web pages(not mvc) and my problem is working with more than one form how do i say to my project that which form button is clicked and another problem is validation because in web form project i was using validation group to separate validations but here i do not know how to deal with it both in client side validate and server side validation here is my codes :
@{
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>