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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:13:47+00:00 2026-05-21T20:13:47+00:00

I have a Razor MVC3 project which has two user records in a form,

  • 0

I have a Razor MVC3 project which has two user records in a form, one for the key contact and one for a backup contact. For example;

public class User
{
    [Required(ErrorMessage = "First name is required")]
    public string FirstName { get; set; }
}

Validation all works well except for the small issue where the user fails to fill out a field, it says ‘First name is required’ but I’d like to point the user to which one of the first name fields is missing. Such as ‘Backup contact first name is required’ or ‘Key contact first name is required’.

Ideally I’d like to leave the [Required] annotation on the class as it is used elsewhere.

This seems like one of those small cases that might have been missed and is not easily achieved, but please prove me wrong.

Ryan

  • 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-21T20:13:48+00:00Added an answer on May 21, 2026 at 8:13 pm

    One way you can accomplish this is with a separate view model for this screen, instead of a single User model with all the error messages. In the new view model, you could have a BackupContactFirstName property, KeyContactFirstName property, etc each with its separate error message. (Alternatively this view model could contain separate User models as properties, but I’ve found that Microsoft’s client validation doesn’t play well with complex models and prefers flat properties).

    Your view model would look like this:

    public class MySpecialScreenViewModel
    {
        [Required(ErrorMessage = "Backup contact first name is required")]
        public string BackupContactFirstName { get; set; }
    
    
        [Required(ErrorMessage = "Key contact first name is required")]
        public string KeyContactFirstName { get; set; }
    }
    

    Then pass your view model to the view like this:

    @model MySpecialScreenViewModel
    ...
    

    Your post controller action would collect the properties from the view model (or map them to separate User models) and pass them to the appropriate data processing methods.

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

Sidebar

Related Questions

I am working on a project which adopted ASP.NET MVC3(Razor) tech. Now, I have
I have a simple PartialView setup in my MVC3 Project using the Razor View
I am currently working on a MVC3 project with Razor. I have switchen on
I have created a sample project using ASP.NET MVC 3 Web Application (Razor) template.
I have a login.jsp page which contains a login form. Once logged in the
When creating a new project for MVC3 I have an option to select a
I have created a website using MVC3 along with the Razor view engine. What
Have just started using Visual Studio Professional's built-in unit testing features, which as I
I'm playing around with Razor + MVC 3 and have a really simple scenario...
In my applications, I often have to use relative paths. For example, when I

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.