Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6199385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:10:41+00:00 2026-05-24T04:10:41+00:00

The ThingController creates a model which contains (amongst other properties) a collection of Things.

  • 0

The ThingController creates a model which contains (amongst other properties) a collection of Things. These can be edited in the view like so:

<form action="@Url.Action("Update", "Thing")" method="post">        
    <table>
        <tr>
            <th>Foo</th>
            <th>Bar</th>
        </tr>        
            @foreach (var thing in ViewData.Model.Things)
            {                
                <tr class="raw-data">
                    <td class="raw-data"><input name="things[@rowCount].Foo" class="raw-data" readonly="readonly" type="text" value="@thing.Foo" /></td>
                    <td class="raw-data"><input name="things[@rowCount].Bar" class="raw-data" type="text" value="@thing.Bar" /></td>
                </tr>                
                rowCount++;
            }
    </table>

    <br />
    <input type="submit" value="OK" />      
</form>

The controller contains the following action, which allows multiple Things to be updated simultaneously:

public ActionResult Update(ThingModel[] things)
{
  ...
}    

I’ve added some validation attributes to properties on the Thing class:

[Required]
[Range(0, 500000, ErrorMessage = "Foo must be within 0 and 500,000.")]
public double Foo{ get; set; }

[Required]
[Range(0, 500000, ErrorMessage = "Bar must be within 0 and 500,000.")]
public double Bar { get; set; }

The thing is, I can’t figure out how to add unobtrusive validation using the TextBoxFor helpers etc.

At this point I think the correct approach is to manually mark up the input fields with the validation attributes, but I was wondering if anyone can point me to some documentation, a tutorial etc. that demonstrates the use of helpers, multiple models and unobtrusive validation?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T04:10:43+00:00Added an answer on May 24, 2026 at 4:10 am

    I had a similar problem where users could dynamically add multiple emails to their account.
    I fixed it with Jquery by adding the validation manually. You should give your form a name and add the validation to all your items. It should be something like this I quess:

        $('#frmYourForm').validate();
        for (var i = 0; i < 'CountOfAllFields'; i++) {
            $('#Things_' + i + '__Foo').rules('add', { required: true, messages: { required: 'The Foo field is required'} });
            $('#Things_' + i + '__Bar').rules('add', { required: true, messages: { required: 'The Bar field is required'} });
        }
    

    Typed from my memory so don’t shoot me if I made an error. I don’t know the exact syntax for the Range thingy but you should look around the Jquery.validate file.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use C# to control a command line application background, which can
I found a good solution for a reusable select view here: select dropdown with
I have a view where I want to perform different actions on the items
How would one go about creating an ipad app that has a similar view
I'm trying to create a custom ActionFilter which operates on a set of parameters
I have a very common situation and a solution, but I would like to
When I touch cancel button in the third view, I want to go back
When I push cancel button in the third view, I want to go back
I like using Models for validation <!-- ViewPage --> <%@ Page Language=C# Inherits=ViewPage<TopicModel> %>
Imagine a typical CakePHP application, in which a Controller passes various bits of data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.