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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T22:33:04+00:00 2026-05-19T22:33:04+00:00

My model contains two objects (Reminders and Users). Each reminder is associated with one

  • 0

My model contains two objects (Reminders and Users). Each reminder is associated with one user.

public class Reminder
    {
    [DisplayName("Subject")]
    [Required(ErrorMessage = "{0}: error message.")]
    [StringLength(200, ErrorMessage = "{0}: error message.")]
    public string Name { get; set; }

    [DisplayName("Supervisor")]
    public User DepartmentSupervisor { get; set; }
    }

public class User 
    {
    [DisplayName("Username")]
    [Required(ErrorMessage = "{0}: error message.")]
    [StringLength(25, ErrorMessage = "{0}: lerror message.")]
    public string Username { get; set; }

    [DisplayName("Email")]
    [StringLength(50, ErrorMessage = "{0}: error message.")]
    [Email(ErrorMessage="Not valid.")]
    public string Email { get; set; }
    }

I’ve defined a viewmodel I use to pass data to my view:

public class RemindersViewModel
    {
        public RemindersViewModel()
        {
            this.Supervisors = new List<SelectListItem>();
        }
        public Models.Reminder Reminder { get; set; }
        public List<SelectListItem> Supervisors { get; set; }
    }

Supervisors is a list of Users (SelectListItem) I use to render a combo.
When I submit the form the controller rebinds the object Reminder:

public ActionResult Edit(Guid id, Models.Reminder Reminder)
{
    if (!ModelState.IsValid)
    {
    // PROBLEM.
    }
}

Everything works fine and I have my reminder associated with the choosen user (username) but, since I don’t need to show the email in the dropdown, the binding can’t fill the field, cause it doesn’t exists in my form.
In the validation process I get an error cause it tries to validate the User model, which is not what I really want.
What’s the best approach dealing with nested models?

  • 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-19T22:33:04+00:00Added an answer on May 19, 2026 at 10:33 pm

    Have you considered using view models? They include only the properties your view requires and the validation for this particular view. So if your view doesn’t require an email you write a view model without an email and the validation passes great. Then inside your controller action you map this view model to the corresponding domain model. AutoMapper is a great tool for this job.

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

Sidebar

Related Questions

I have a model that contains one-to-one fields to other models. I over rid
I'm trying to access a relationship (one to many) programatically. My Data model contains
The code below consists of two classes : SmartForm (simple model class) SmartForms (plural
i have an entity that contains two other entities with @ManyToOne relationship. @Entity public
For the app I'm currently working on, one of my main ViewControllers contains two
My scenario is this: I have two listbox's, one that contains all my database
I'm building a webapp that contains an IFrame in design mode so my user's
In Model-View-Presenter pattern where should we write validations of user input.
I have a rails model that looks something like this: class Recipe < ActiveRecord::Base
class Tag(models.Model): name = models.CharField(maxlength=100) class Blog(models.Model): name = models.CharField(maxlength=100) tags = models.ManyToManyField(Tag) Simple

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.