Results 1 to 2 of 2

Thread: [RESOLVED] Multiple forms with validation in a single view?

  1. #1

    Thread Starter
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Resolved [RESOLVED] Multiple forms with validation in a single view?

    If I have two separate forms on a view, each containing a single dropdownlist and submit button, what's the best way to pass the list values to the view so I can perform validation on each dropdownlist/form separately?

    I've currently got a ViewModel with two IEnumerable<SelectListItem> properties (both with [Required]) for the lists and assigning that to @Html.DropDownList(), but I can't seem to get the associated @Html.ValidationMessageFor() to trigger when submitting the list with the default "-- Select --" value.

    Code:
    @using (Html.BeginForm("Action1", "Controller"))
    { 
        @Html.AntiForgeryToken("Action1TokenSalt")
        <fieldset>
            <legend>List1</legend>
            <div class="editor-field">
                @Html.DropDownList("FooId", Model.List1Items, "-- Select --")
                @Html.ValidationMessageFor(m => m.List1Items)
            </div>
            <p>
                <input type="submit" value="Submit 1" />
            </p>
        </fieldset>
    }
    @using (Html.BeginForm("Action2", "Controller"))
    { 
        @Html.AntiForgeryToken("Action2TokenSalt")
        <fieldset>
            <legend>List2</legend>
            <div class="editor-field">
                @Html.DropDownList("FooId", Model.List2Items, "-- Select --")
                @Html.ValidationMessageFor(m => m.List2Items)
            </div>
            <p>
                <input type="submit" value="Submit 2" />
            </p>
        </fieldset>
    }
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

  2. #2

    Thread Starter
    Frenzied Member tr333's Avatar
    Join Date
    Nov 2004
    Location
    /dev/st0
    Posts
    1,605

    Re: Multiple forms with validation in a single view?

    Just noticed that I had forgotten to include the jQuery validation libs on the page.
    CSS layout comes in to the 21st century with flexbox!
    Just another Perl hacker,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width