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 7986005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T11:43:21+00:00 2026-06-04T11:43:21+00:00

Currently i have a customer class that the user can partially create, and finish

  • 0

Currently i have a customer class that the user can partially create, and finish the detailed information down the line. For example it looks like this

New Customer

    [Required(ErrorMessage = "Business name is required.")]
    [Display(Name = "Business Name:")]
    public string BusinessName { get; set; }

    [Display(Name = "Address:")]
    public string Address { get; set; }

    [Display(Name = "City:")]
    public string City { get; set; }

    [Display(Name = "State:")]
    public string State { get; set; }

    [Display(Name = "Zip:")]
    public string Zip { get; set; }

Customer Checkout

    [Required(ErrorMessage = "Business name is required.")]
    [Display(Name = "Business Name:")]
    public string BusinessName { get; set; }

    [Required(ErrorMessage = "Address is required.")]
    [Display(Name = "Address:")]
    public string Address { get; set; }

    [Required(ErrorMessage = "City is required.")]
    [Display(Name = "City:")]
    public string City { get; set; }

    [Required(ErrorMessage = "State is required.")]
    [Display(Name = "State:")]
    public string State { get; set; }

    [Required(ErrorMessage = "Zip is required.")]
    [Display(Name = "Zip:")]
    public string Zip { get; set; }

when the user goes to checkout i need to make sure that they do finish filling out the information if some is missing.
My thought process was to create a Customer Checkout class populated with the information from when they created a new customer and check to see if its valid before passing them along to checkout. My issue is the only way i know to do that is to check each field against string.isNullOrEmpty() but i know there has to be a better way. I will have to check 25 fields like this. I know that you can check if a Model is valid, but i need to do this at a class level in my Data Access Layer checking to make sure all[required] fields have data. Hopefully i am just overlooking something

almost like I need some way to do something like

bool hasErrors = false 

foreach attribute in my class 
if it is marked as [required]
check to make sure not null or empty
if it is set hasErrors = true

thanks!

  • 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-04T11:43:23+00:00Added an answer on June 4, 2026 at 11:43 am

    If performance is not a consideration you can use reflection to automatically validate your object.

    static class ObjectValidator
    {
        public static bool IsValid(object toValidate)
        {
            Type type = toValidate.GetType();
            var properties = type.GetProperties();
            foreach(var propInfo in properties)
            {
                var required = propInfo.GetCustomAttributes(typeof(RequiredAttribute), false);
                if (required.Length > 0)
                {
                    var value = propInfo.GetValue(toValidate, null);
                    // Here you'll need to expand the tests if you want for types like string
                    if (value == default(propInfo.PropertyType))
                        return false;
                }
            }
            return true;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Currently I have this code var App = Ember.Application.create(); App.user = Ember.Object.create({ people: customers
I currently have links w/ class=ajax that I want to retrieve the element with
I have a domain model that includes something like this: public class Customer :
I currently have the following (simplified) class / db schema: Entity Prospect Customer +-
I have a customer who is currently using Excel to do their staff planning.
I currently have a need for a custom ListViewItem class - let's call it
I currently have a query that looks like this: SELECT NON EMPTY ([Measures].[TOTAL]) ON
I have the following partial methods in my partial class that is attached to
I currently have a menu with subitems that is being stored in this dictionary
Currently I'm using a base class for some Customer model classes. As defined as

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.