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

  • Home
  • SEARCH
  • 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 7958455
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:25:32+00:00 2026-06-04T04:25:32+00:00

I got a class that inherits IValidatableObject which my validations are validated through IEnumerable<ValidationResult>

  • 0

I got a class that inherits IValidatableObject which my validations are validated through IEnumerable<ValidationResult> function. Inside this function I manage to check all the fields and return one ValidationResult message.

However, My problem is the membernames.ToArray() is only passing one value. I prove it during debegging the View page and when it checks the field if it is valid using Html.ViewData.ModelState.IsValid("<fieldname>")

Below is the code when I return the ValidationResult message with all the fields that are not valid. The string.Join(",", membernames.ToArray()) will return a collection of the fields. (i.e “FirstName”, “LastName”)

List<string> membernames = new List<string>();

//Firstname
if (FirstName.Trim() == string.Empty)
{
   isValid = false;
   membernames.Add(@"""FirstName""");
}

//Lastname
if (LastName.Trim() == string.Empty)
{
   membernames.Add(@"""LastName""");
   isValid = false;
}

if (!isValid)
{
    yield return new ValidationResult("Please complete all fields marked with *", new[] { string.Join(",", membernames.ToArray()) });
}

Do I pass the correct type in the new[] { .. } ?

Please advise. Thanks in advance.

  • 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-06-04T04:25:33+00:00Added an answer on June 4, 2026 at 4:25 am

    In Mvc3 :

    in Controller:

    ModelState.AddModelError("FirstName", "FirstName Minimum 2 Char");
    ModelState.AddModelError("FirstName", "FirstName Maximum 20 Char");
    ModelState.AddModelError("LastName", "Error Message");
    

    if You Want only one Error Message for All property:

    ModelState.AddModelError("", "First Error Message");
    ModelState.AddModelError("", "Second Error Message");
    

    in View:

    @using (Html.BeginForm()) {
        @Html.ValidationSummary()
    
        @Html.LabelFor(model => model.FirstName)
        @Html.EditorFor(model => model.FirstName)
        @Html.ValidationMessageFor(model => model.FirstName)
    
        @Html.LabelFor(model => model.LastName)
        @Html.EditorFor(model => model.LastName)
        @Html.ValidationMessageFor(model => model.LastName)
    
       //other fields...
    }
    

    don’t forget jquery and Validation plugin:

    <script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got this code in the InitInstance function of a class that extends WinApp:
I'm trying to create a class that inherits from ListViewItemCollection, and I got this
I have a class ShipmentsCollection that inherits ObservableCollection which contains shipment objects (entities). This
I've got a class that inherits from an interface. That interface defines an event
I've got a method in a class that's writing to some string, which calls
I've got a 'MyDataTable' class that inherits from System.Data.DataTable I've implemented ISerializable in my
I've got an abstract class (Object2D), and several class that inherits Object2D (DisplayObject2D for
I've got two classes: a template class, and a regular class that inherits from
I've got a simple class that inherits from Collection and adds a couple of
I've got a custom class that inherits from UITableViewCell. I know how to dynamically

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.