Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net razor web pages validation and using multiple forms

Tags:

razor

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>
like image 514
asp.net developer Avatar asked Apr 30 '26 12:04

asp.net developer


1 Answers

Check out this link for handling multiple form requests http://forums.asp.net/t/1678062.aspx/1

You can handle validation in each sub section. Hope that helps

like image 58
Royston Yinkore Avatar answered May 04 '26 06:05

Royston Yinkore



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!