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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T08:21:12+00:00 2026-06-14T08:21:12+00:00

I have a complex view model which has some subclasses. For the sake of

  • 0

I have a complex view model which has some subclasses. For the sake of a simple example, let’s assume there’s one subclass.

That subclass is displayed by rendering a partial view. The user can toggle that view in the interface, completely hiding the whole thing.

Now there are two valid input options:

  1. The user chooses to hide the partial and doesn’t fill in anything. The whole thing should be ignored.
  2. The user chooses to view the partial, now he has to fill it in. Some of the fields are required, some are not.

What’s a good way to handle this is MVC validation? I cannot mark the fields as Required, since the postback will post the empty values and the server side logic will say ModelState.IsValid is false beacuse there are fields missing.

Of course I can lose the [Required] attributes and do the checks manually myself, but I was wondering if there’s no better way to get the same result.

  • 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-14T08:21:13+00:00Added an answer on June 14, 2026 at 8:21 am

    The simplest way of doing this is like this ASP.NET MVC 3 Data Annotation: Add validation dynamically.

    For a harder (a bit nicer) solution read this: DataAnnotations "NotRequired" attribute

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

Sidebar

Related Questions

There is a view to update a complex model(Transaction). Complex model has properties which
I have a fairly complex view that has multiple forms, lots of validations on
I have a materialized view of a complex join, which I would like to
At which layer (Model, View, Controller) of MVC should permission logic be handled? Let
In ASP.NET MVC there is Model, View and Controller. MODEL represents entities which are
I have a Post model and a View model (which logs the view of
I have a 'Complex' model which hasMany Unit. My model associations are correct, everything
We have written a pretty complex web application which has following requirements: It has
I have to build a more complex custom view in Android. The final layout
I am using WCF and REST, and I have complex types, which are working

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.