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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:39:27+00:00 2026-05-14T15:39:27+00:00

I have repository class in asp.net mvc which has this, public Material GetMaterial(int id)

  • 0

I have repository class in asp.net mvc which has this,

 public Material GetMaterial(int id)
    {
        return db.Materials.SingleOrDefault(m => m.Mat_id == id);
    }

And my controller has this for details action result,

ConstructionRepository consRepository = new ConstructionRepository();
public ActionResult Details(int id)
    {
        Material material = consRepository.GetMaterial(id);
        return View();
    }

But why i get this error,

The parameters dictionary contains a null entry for parameter 'id' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult Details(Int32)' in 'CrMVC.Controllers.MaterialsController'. To make a parameter optional its type should be either a reference type or a Nullable type.
Parameter name: parameters

Any suggestion…

  • 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-14T15:39:28+00:00Added an answer on May 14, 2026 at 3:39 pm

    You’re getting the error because you’re not passing an id to the controller method.

    You basically have two options:

    1. Always pass a valid id to the controller method, or
    2. Use an int? parameter, and coalesce the null before calling GetMaterial(id).

    Regardless, you should check for a null value for material. So:

    public ActionResult Details(int? id) 
    { 
        Material material = consRepository.GetMaterial((int)(id ?? 0)); 
        if (id == null)
            return View("NotFound");
        return View(); 
    }
    

    Or (assuming you always pass a proper id):

    public ActionResult Details(int id) 
    { 
        Material material = consRepository.GetMaterial(id); 
        if (id == null)
            return View("NotFound");
        return View(); 
    }
    

    To pass a valid id to the controller method, you need a route that looks something like this:

     routes.MapRoute(
         "Default",
         "{controller}/{action}/{id}",
         new { controller = "Home", action = "Index", id="" }
     );
    

    And an URL that looks like this:

    http://MySite.com/MyController/GetMaterial/6  <-- id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an ASP.NET MVC app which has a bootstrapper class that configures log4net
I have a repository class and it has this, using System; using System.Collections.Generic; using
On my ASP.NET MVC 3 project, I have implemented the repository pattern inside a
I have an ASP.NET MVC 3 (Razor) Web Application, with a particular page which
I have this simple Delete Get and Post methods in a asp.net mvc application
I currently have an ASP.NET MVC 3 project, plus a class library project, that
I have been using http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/implementing-the-repository-and-unit-of-work-patterns-in-an-asp-net-mvc-application as guidance to help me create a repository.I have
Iam using .NET 3.5. I have asp.net mvc app. There is base controller: public
I have a repository Class which takes in a ObjectContext called TestDB. I when
I have a Repository Class with the following method... public T Single<T>(Predicate<T> expression) {

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.