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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:13:30+00:00 2026-05-28T14:13:30+00:00

I use EntityFramework CodeFirst MVC3. In my model I defined a nullable property like

  • 0

I use EntityFramework CodeFirst MVC3. In my model I defined a nullable property like this:

public class PostFullViewModel
{
    public int PostID { get; set; }
    ...
    public DateTime? PublishDate { get; set; }
    ...
}

Here is my Create action controller:

public ActionResult Create()
    {
        PostCreateViewModel viewModel = new PostCreateViewModel
        {
            PostToCreate = new PostFullViewModel(),
            Authors = m_AccountBusiness.GetAllUsers().Select(x => new SelectListItem { Text = x.UserName, Value = x.UserID.ToString() })
        };

        return View(viewModel);
    }

In my create view:

@model PostCreateViewModel

@using (Html.BeginForm())
{
    @Html.LabelFor(model => model.PostToCreate.PublishDate)
    @Html.EditorFor(model => model.PostToCreate.PublishDate)
    ...
}

I got an error on the EditorFor line:

The model item passed into the dictionary is null, but this dictionary requires a non-null model item of type 'System.DateTime'.

How can I proceed to have my creation view showing the PublishDate empty?

Thanks.

  • 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-28T14:13:31+00:00Added an answer on May 28, 2026 at 2:13 pm

    I guess you defined a custom editor template for the DateTime type (~/Views/Shared/EditorTemplates/DateTime.cshtml or ~/Views/XXX/EditorTemplates/DateTime.cshtml where XXX is your current controller name) which is strongly typed to DateTime instead of DateTime? like this:

    @model DateTime
    ...
    

    So you could change its type to DateTime?.

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

Sidebar

Related Questions

I have an example class book : public class Book { [Key] public int
As I understand it, Crystal Reports can use EntityFramework, is the correct? I'd rather
I'm trying to use EntityFramework to work with MySQL database from c#. I'm using
Assume we have an ASP.NET MVC3 Web site that makes use of Entity Framework
Is there a way to use EntityFramework 4.3 beta with migrations with MySql database?
I'm trying to use SLQ server compact edition 4 together with entityframework 4.1 with
I am trying to use ADO.Net Codefirst feature of latest Entity Framework 4.0. As
I am using MVC3 with Entity Framework Code First. I have the following model.
I am trying to use MVC3 with the Entity framework with Code First, but
When I use Entity Framework codefirst I can use the following code to 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.