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

The Archive Base Latest Questions

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

I’m just trying to build a view but I’m getting the following error: System.InvalidOperationException:

  • 0

I’m just trying to build a view but I’m getting the following error:

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

Now, I know why this is coming up, the particular field in the database is null, however it is supposed to be, as this is something that is edited at a later date. Here is my code:

Action

public ActionResult View(Int64? Id)
    {

        ModelContainer ctn = new ModelContainer();
        var item = from t in ctn.Items where t.ItemID == Id select t;
        return View(Item.First());
    }

Main View

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Administrator.Master" Inherits="System.Web.Mvc.ViewPage<myApp.Data.Item>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    View
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <% Html.RenderPartial("Details", Model); %>

</asp:Content>

<asp:Content ID="Content3" ContentPlaceHolderID="Header" runat="server">
<h1>Details - <%= Model.MainItem %></h1>
</asp:Content>

Partial View

<%@ Control Language="C#" Inherits="System.Web.Mvc.ViewUserControl<myApp.Data.Item>" %>
<%@ Import Namespace="myApp.Supplier.Web.Extensions" %>

    <fieldset>

        <legend>Information</legend>

        <div class="fieldset">

            <%= Html.LabelFor(m => m.MainItem)%>
            <%= Html.DisplayFor(m => m.MainItem, "FormTextShort")%><br />
            <%= Html.LabelFor(m => m.Supplier.Name)%>
            <%= Html.DisplayFor(m => m.Supplier.Name, "FormTextShort")%><br />
            <%= Html.LabelFor(m => m.ProductCode)%>
            <%= Html.DisplayFor(m => m.ProductCode, "FormTextShort")%><br />
            <%= Html.LabelFor(m => m.Product.SubmissionDate)%>
            <%= Html.DisplayFor(m => m.Product.SubmissionDate, "FormDateShort")%><br />
            <%= Html.LabelFor(m => m.Product.SentForRepair)%>
            <%= Html.DisplayFor(m => m.Product.SentForRepair, "FormDateShort")%><br />
         </div>

    </fieldset>

In this case, the x.Product.SentForRepair date is left null, because at the time of submission, it has not yet been sent away. I have other fields like this, e.g. totalCost, etc however for simplicity I have not included them here. If I comment out the SentForRepair lines, the View displays perfectly with the other information.

I’d be so so grateful if someone could point me in the right direction as to how to get around this error!! 🙂

  • 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-19T13:33:23+00:00Added an answer on May 19, 2026 at 1:33 pm

    Inside the Display template you need to check for null (after making it strongly typed to DateTime?):

    <% if (Model.HasValue) { %>
        <%= Html.Encode(Model.Value.ToString("yyyy-MM-dd")) %>
    <% } %>
    

    or if you wanted to simply provide a custom date format you could remove the FormDateShort display template and decorate your view model property with the [DisplayFormat] attribute:

    [DisplayFormat(NullDisplayText = "", DataFormatString = "{0:yyyy-MM-dd}")]
    public DateTime? SentForRepair { get; set; }
    

    and then simply:

    <%= Html.DisplayFor(m => m.Product.SentForRepair)%>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I'm looking for suggestions for debugging... If you view this site in Firefox or
Seemingly simple, but I cannot find anything relevant on the web. What is the
this is what i have right now Drawing an RSS feed into the php,
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I've got a string that has curly quotes in it. I'd like to replace
I want use html5's new tag to play a wav file (currently only supported

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.