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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:29:38+00:00 2026-05-20T18:29:38+00:00

I have two Dictionary<string, byte> properties in my model that should validate properly with

  • 0

I have two Dictionary<string, byte> properties in my model that should validate properly with from 0 to 5 items. For example the property skill (string dropDownListLabel, byte years).

Because I need to support non-javascript clients, I render all 5 input pairs to the browser, only binding existing dictionary items, and life is great. This gives 5 empty input pairs for a new plain HTML form, each with unique input names, which I also want.

Here’s the serialization (input names) I use:

skill[0].Key = "", skill[0].Value = ""
 ... three more pairs ...
skill[4].Key = "", skill[4].Value = ""

But on POST, for Key/Value pairs with neither Key nor Value specified, DefaultModelBinder validation errors result on Value.

Is there a type and serialization I can use that will validate in DefaultModelBinder when both or neither Key and Value are POSTed, so MVC does as much work for me as possible, only adding pairs into a collection when they have content?

Thanks,
Shannon

  • 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-20T18:29:38+00:00Added an answer on May 20, 2026 at 6:29 pm

    You cannot bind an empty string to a value type (byte) so the default model binder marks your model as invalid. If you want to allow empty values you should use a nullable byte:

    Dictionary<string, byte?>
    

    UPDATE:

    Another possibility is to use a collection of a custom type containing two properties each representing respectively the key and the value. Then use strongly typed helpers and editor templates in your view so that you don’t have to worry about the wire format and finally you will need to ensure that the keys are unique so you will need a custom validator. Personally I use FluentValidation.NET for this part but if you are using data annotations you will need a custom attribute which will be used to decorate the collection property in the view model.

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

Sidebar

Related Questions

I have two dictionaries with the same structure: Dictionary<string, int> foo = new Dictionary<string,
I have two complex dictionaries in the form Dictionary<string, Dictionary<string, Dictionary<string, List<string>>>> So as
I have two dictionaries like Dictionary<String, String> one = new Dictionary<string, string> { {
I have two applications written in Java that communicate with each other using XML
I have two arrays of animals (for example). $array = array( array( 'id' =>
I have two identical tables and need to copy rows from table to another.
A problem I'm trying to solve: given that you have two distinct strings composed
I have a List of String like List<String> MyList=new List<String>{A,B}; and a Dictionary<String, Dictionary<String,String>>
I have a JSON multi-level response that I need to deserialize and from the
I have two arrays of System.Data.DataRow objects which I want to compare. The rows

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.