locked
validation Group MVC RRS feed

  • Question

  • User-1952516322 posted

    Hello,

    I have a text boxes for save and text boxes for search, but I want when user click on save to check the validation for specific text boxes not all. ( exactly like Validation Group in Web Forms )

    By the way, my view is strongly type view, and I have textbox for search > Name, also in save section I have textbox for Name.  But when user click on search to check just the textbox on search section...etc

    Tuesday, March 12, 2019 12:28 PM

Answers

  • User-1038772411 posted

    The easiest thing to do is to put them in two different forms. So the input for productID goes in form1and the rest go in form2

    @using (Html.BeginForm())
    {
       // inputs for form 1
       <input type="submit" />
    }
    
    @using (Html.BeginForm())
    {
       // inputs for form 2
       <input type="submit" />
    }

    I Used same When I need to do. i refer this link

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 12, 2019 12:44 PM
  • User1520731567 posted

    Hi Khalid Salameh,

    but I want when user click on save to check the validation for specific text boxes not all

    Do you want that when click submit button,verifying only a subset of the fields?

    If so,I suggest you could use JQuery validate plugin, and create custom validation.

    If that is the case, I suggest you could refer to the following code:

      $("#Form").validate({
                rules: {
                    field1: {
                        required: true
                    },
                    field2: {
                        required: true,
                        maxlength: 255
                    }
    ... }, messages: { field1: { required: 'it is not null' }, field2: { required: 'it is not null', maxlength: 'the max length is 255' }
    ... }, });

    You could refer to the following articles:

    https://jqueryvalidation.org/

    http://www.websitecodetutorials.com/code/jquery-plugins/jquery-validation.php

    Best Regards.

    Yuki Tao

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 13, 2019 10:03 AM

All replies

  • User-1038772411 posted

    The easiest thing to do is to put them in two different forms. So the input for productID goes in form1and the rest go in form2

    @using (Html.BeginForm())
    {
       // inputs for form 1
       <input type="submit" />
    }
    
    @using (Html.BeginForm())
    {
       // inputs for form 2
       <input type="submit" />
    }

    I Used same When I need to do. i refer this link

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 12, 2019 12:44 PM
  • User1520731567 posted

    Hi Khalid Salameh,

    but I want when user click on save to check the validation for specific text boxes not all

    Do you want that when click submit button,verifying only a subset of the fields?

    If so,I suggest you could use JQuery validate plugin, and create custom validation.

    If that is the case, I suggest you could refer to the following code:

      $("#Form").validate({
                rules: {
                    field1: {
                        required: true
                    },
                    field2: {
                        required: true,
                        maxlength: 255
                    }
    ... }, messages: { field1: { required: 'it is not null' }, field2: { required: 'it is not null', maxlength: 'the max length is 255' }
    ... }, });

    You could refer to the following articles:

    https://jqueryvalidation.org/

    http://www.websitecodetutorials.com/code/jquery-plugins/jquery-validation.php

    Best Regards.

    Yuki Tao

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, March 13, 2019 10:03 AM
  • User-1952516322 posted

    Thanks, it is easiest way

    Thursday, March 14, 2019 11:17 AM