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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T21:45:23+00:00 2026-06-18T21:45:23+00:00

I have the following viewModel: public class CreateCardViewModel { [HiddenInput(DisplayValue = false)] public int

  • 0

I have the following viewModel:

public class CreateCardViewModel
    {
        [HiddenInput(DisplayValue = false)]
        public int SetId { get; set; }

        [Required]
        public ICollection<Side> Sides { get; set; }

        [Required]
        [DataType(DataType.Date)]
        public DateTime DateCreated { get; set; }

        [Required]
        public bool IsReady { get; set; }

    }

And the following actions defined for Create:

[HttpGet]
        public ActionResult Create(int setId)
        {
            var model = new CreateCardViewModel();

            // attach card to current set
            model.SetId = setId;

            // create a new Side
            var side = new Side() {Content = "Blank Side"};

            // Add this to the model's Collection
            model.Sides = new Collection<Side> { side };

            return View(model);
        }

        [HttpPost]
        public ActionResult Create(CreateCardViewModel viewModel)
        {
            if (ModelState.IsValid)
            {
                var set = _db.Sets.Single(s => s.SetId == viewModel.SetId);
                var card = new Card {Sides = viewModel.Sides};

                set.Cards.Add(card);

                _db.Save();
            }
            return View(viewModel);


        }

When I try to create a new card, the Sides property of the viewModel is null, so the ModelState is coming up as null. I can’t quite figure out why that initial Side isn’t getting passed with the model.

My View looks like this:

<h2>Create</h2>

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>CreateCardViewModel</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.SetId)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.SetId)
            @Html.ValidationMessageFor(model => model.SetId)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.DateCreated)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.DateCreated)
            @Html.ValidationMessageFor(model => model.DateCreated)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.IsReady)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.IsReady)
            @Html.ValidationMessageFor(model => model.IsReady)
        </div>

        <p>
            <input type="submit" value="Create" />
        </p>
    </fieldset>
}
  • 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-18T21:45:25+00:00Added an answer on June 18, 2026 at 9:45 pm

    There’s nothing in your View that is bound to the Sides property of your ViewModel. Without anything in the form to hold the value of that property, it will be null when model binding occurs. You’ll need to somehow capture the Side in your form – how are you adding to/removing from this property? Via user interaction that should take place on the form?

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

Sidebar

Related Questions

I have the following viewModel: namespace Flashcard.Models { public class CreateCardViewModel { [HiddenInput(DisplayValue =
I have a viewModel that contains the following: public class CreateCardViewModel { [HiddenInput(DisplayValue =
I have following ViewModel: public class Bulletin1ViewModel { [Required] public String NumberDelegations { get;
I have the following ViewModel: public class CheckListInfo { public int CheckListQuestionID { get;
I have the following ViewModel: public class ViewModel { public Address Address {get;set;} [DisplayName(State)]
I have the following ViewModel public class NewCustomerViewModel { public long CustomerId {get;set;} public
I have the following ViewModel public class RecommendationModel { public List<CheckBoxItem> CheckBoxList { get;
I have a ViewModel as such: public class EmployeeViewModel { Employees employee{ get; set;
I have following ViewModel containing NumberOfAdults fields. public class SearchView { public int NumberOfAdults
I have the following ViewModel public class ShowQuestionsViewModel { public String CategoryName { get;

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.