binding stored procedure in ASP.NET MVC and Entity Framework

Hi experts,

I saw this example and so I decided do this example.
Execute Stored Procedure using Entity Framework in ASP.NET MVC
http://dotnetvisio.blogspot.com/2014/01/execute-stored-procedure-using-entity.html

I'm using Visual Studio 2013 Ultimate and Sql Server 2008 R2.

On this example, it doesn't have the code or script to create the table in the example.

Here are the script I created, to create the table and stored procedures.

EmpTable

CREATE TABLE [dbo].[EMPTABLE](
	[ID] [int] NOT NULL,
	[DEPTID] [int] NULL,
	[NAME] [varchar](50) NULL,
	[COUNTRY] [varchar](50) NULL,
	[MARRIED] [char](1) NULL,
 CONSTRAINT [PK_EMPTABLE] PRIMARY KEY CLUSTERED 
(
	[ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
INSERT [dbo].[EMPTABLE] ([ID], [DEPTID], [NAME], [COUNTRY], [MARRIED]) VALUES (1, 1, N'RAJESH', N'INDIA', N'Y')
INSERT [dbo].[EMPTABLE] ([ID], [DEPTID], [NAME], [COUNTRY], [MARRIED]) VALUES (2, 1, N'SURESH', N'US', N'Y')
INSERT [dbo].[EMPTABLE] ([ID], [DEPTID], [NAME], [COUNTRY], [MARRIED]) VALUES (3, 1, N'ALEX', N'BRAZIL', N'N')
INSERT [dbo].[EMPTABLE] ([ID], [DEPTID], [NAME], [COUNTRY], [MARRIED]) VALUES (4, 2, N'LANDER', N'IRAN', N'Y')
INSERT [dbo].[EMPTABLE] ([ID], [DEPTID], [NAME], [COUNTRY], [MARRIED]) VALUES (5, 1, N'JOEL', N'INDIA', N'N')
INSERT [dbo].[EMPTABLE] ([ID], [DEPTID], [NAME], [COUNTRY], [MARRIED]) VALUES (6, 2, N'ALBERT', N'INDIA', N'N')
INSERT [dbo].[EMPTABLE] ([ID], [DEPTID], [NAME], [COUNTRY], [MARRIED]) VALUES (7, 3, N'KRISTY', N'US', N'Y')
INSERT [dbo].[EMPTABLE] ([ID], [DEPTID], [NAME], [COUNTRY], [MARRIED]) VALUES (8, 3, N'KIRUBA', N'INDIA', N'Y')
INSERT [dbo].[EMPTABLE] ([ID], [DEPTID], [NAME], [COUNTRY], [MARRIED]) VALUES (9, 1, N'YUSAN', N'US', N'Y')
INSERT [dbo].[EMPTABLE] ([ID], [DEPTID], [NAME], [COUNTRY], [MARRIED]) VALUES (10, 2, N'KREG', N'UK', N'Y')

Open in new window


FETCHEMPLOYEES stored procedure

CREATE PROCEDURE [dbo].[FETCHEMPLOYEES]
AS
BEGIN
      SELECT [ID]
            ,[DEPTID]
            ,[NAME]
            ,[COUNTRY]
            ,[MARRIED]
      FROM [MVCEmployeeDB].[dbo].[EMPTABLE]
END
GO

Open in new window


FETCHEMPLOYEE stored procedure

CREATE PROCEDURE [dbo].[FETCHEMPLOYEE](@ID INT)
AS
BEGIN
      SELECT [ID]
            ,[DEPTID]
            ,[NAME]
            ,[COUNTRY]
            ,[MARRIED]
      FROM [MVCEmployeeDB].[dbo].[EMPTABLE]
      WHERE [ID] = @ID
END
GO

Open in new window



So i followed the steps described in the link above.

My Visual Studio 2013 MVC 4 project directory looks like this. I used the MVC 4 blank template and razor when I created my project.

my project directory
When I run my project I get this error message on my view Index.cshtml

my error
You can download my Visual Studio project here which contains my code:

Download Visual Studio 2013 Project

Anyone know why I am getting this error? What did I do wrong?
LVL 1
maqskywalkerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gary DavisDir Internet SvcsCommented:
This is in the controller. The first action is not passing the model to the view so in the view, Model is null causing the exception.

       
 public ActionResult Index()
        {
            List<EMPTABLE> result = mod.GetEmployees();
            return View();
        }

        public ActionResult Details(int id)
        {
            EMPTABLE result = mod.GetEmployee(id);
            return View(result);
        }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.