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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:27:31+00:00 2026-05-27T14:27:31+00:00

I get below error when I try to add controller to my ASP.NET MVC

  • 0

I get below error when I try to add controller to my ASP.NET MVC 3 intranet project

Object reference not set to an instance of object

I am following an article http://sumitmaitra.wordpress.com/2011/11/13/fun-with-signalr/ to develop SignalR application.

I doubt that after installing SignalR something went wrong but not very sure about it.

Edit

Model code:

public class BlogPost
{
    [Key]
    public int Id { get; set; }
    [Required]
    public string Title { get; set; }
    public string Post { get; set;}
}

DbContext:

namespace SignalR.Models
{
    public class BlogPostContext : DbContext
    {
        public DbSet<BlogPost> BlogPosts { get; set; }
    }
}

Controller:

Controller

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

    I don’t know anything about SignalR but i’m pretty sure the problem has something to do with your view trying to render HTML for properties of a null object.

    I had a skim through the article and cannot see any reference to the actual database that stores the data and no code was provided to generate the database from your code (and the post’s author is not clear on wether you will be connecting to an existing database or generating one).

    See here for example of mapping your code to an EXISTING database.

    If you don’t already have an existing database then you need to tell your Entity Framework code to generate one; This article will show you how to do that (the stuff you need is towards the bottom of the post).

    Now, looking at the way you have set up your entity class and assuming you haven’t already done any of the things mentioned in the two articles, Entity Framework should be creating a database for you automatically (which is the default behaviour – not sure what happens if you don’t have SQL Server Express or greater installed though). Have you checked to see if you have a database in your SQL server instance? It should be called BlogPostContext. Fill this with some data and things should now work.

    So why are you getting this problem? At the moment you either have

    1. No database, OR
    2. A database with no data.

    This means your controllers are either

    1. Requesting data from something that doesn’t exist, OR
    2. Requesting data from an empty database

    The result you will get back from both scenarios is a null object. This null object is then passed to your views which are then trying to iterate over the null object and generating your exception.

    You can verify this in two ways.

    1. Check for a null object in your views and only output HTML based on your model if the null check returns false.
    2. Replace your database retrieval logic in your controllers for some code which generates some dummy blog data and pass this into your view instead.

    For solution 1 something like the following in your view:

    @if (Model == null)
    {
        <span>No data!</span>
    }
    @else
    {
        // All the auto generated view code goes here...
    }
    

    For solution two you need to replace the data retrieval code in your controller. So remove any code like this;

    BlogPost blogPost = db.BlogPosts.Find(id)
    

    and replace it with something like this;

    BlogPost blog = new BlogPost()
    {
        Title = "Use Entity Framework Code-First";
        Post = "blog post body goes here..."
    };
    
    IEnumerable<BlogPost> posts = new List<BlogPost>();
    posts.Add(blog);
    

    Note: These two solutions are for demonstrating the problem to you and you should revert to using the data retrieval code once you have correctly setup your database.

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

Sidebar

Related Questions

I will get the error below randomly when I'm running an asp.net application I
I get the following error when I try and execute the code down below.
When I try to use the code below I get a duplicate variable error
I get the below error when I try to link resources in a dll.
Currently I'am working on an MVC project in which I try to get a
I have a website that I get the below error on whenever I navigate
Does anyone know how to get the below to report a javascript error? (any
I'm trying to call the SQL statement below but get the following error: System.Data.SqlClient.SqlException:
I get the following error with the code below. expected constructor, destructor, or type
I get the following error in the query below: #1064 - You have an

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.