Click here to Skip to main content
13,588,538 members
Rate this:
Please Sign up or sign in to vote.
See more:
hello?? :) :confused:

can some body tell where i can find a video tutorial or how i can view a store procedure on to a web page using mvc2? (result view)
its bin killing me all week.

can somebody help me please I'm new at this.

thank you,
Posted 7-Mar-11 10:55am
Updated 7-Mar-11 14:14pm
Albin Abel 7-Mar-11 21:23pm
If you know how to use sql from model then the same way you can use stored procedure. Use the command type stored procedure. Post your code spinets, will try to help if anything wrong in it
SabirB 21-Apr-11 4:34am
Hey did you find out the solution?
Even i am also struggling on that as i am new to MVC2....
Guys please let me know if any body have implemented the same...

Thank you Very much.

Rate this: bad
Please Sign up or sign in to vote.

Solution 2

If your using a ORM like Entity Framework you can call the list of items in your Controller like this.

//these are the parameters that will pass into a storedprocedure
public ActionResult SearchList()

                                      var model = new Models.SearchBy();
                                      model.para1 = 0;
                                      model.para2 = 0;
                                      model.para3 = DateTime.Today;
                                      model.para4 = DateTime.Today;

                                         return View(model);

//and then call the list passing the parameters into it the stored procedure

public ActionResult List(Models.SearchBy dr)
   listEntities n = new  listEntities();
   var model = n.Get_Gamelist(dr.para1, dr.para2,dr.para3,dr.para4);/*but put them in the right place*/
   return View(model);

i hoop this was helpful.
SabirB 21-Apr-11 8:40am
Hi Thanks for information
but my issue is some thing different which i have described below in steps.
1. created a ADO.Net Entity Data Model in Models(MVC2 - Architecture) by name Entites.edmx
2.configured database connectivity by selecting Generate from database.
3. selected all tables, views and Stored procuders from db(SQL2008)
4.finally i got two files added to my Models one is -Entites.edmx and other Entites.Designer.cs.
5. And i got all the tables in Entites.edmx
6.And all the tables, views in well described way with column name and data types which is good in Entites.Designer.cs class. my controller class added the namespace of Models and created a private object of models to controller class.
8.when i type model object.,then i am getting all the tables and views name.

9.But i am not getting the storedprocedures name which i need to bind the grid???????

I hope i described in well method.

please answer me if anybody has implemented earlier.

Herfst 21-Apr-11 9:14am
so the issue is that you want to get the storedprocedure from Entites.edmx?
you can do it in the same way as the example, but in your situation the Entites.edmx and Entites.Designer.cs. Just look at the designer.cs. and look what the name is for your ENTITIES. mine was ListEntities.
(just copy and replace that name)
Herfst 21-Apr-11 9:44am
oh sorry about that you have to add a funtion import of your storedprocedure first. follow these steps. go to Entities.emdx-> right click on a empty space -> choose model browser-> and in your model browser go to one of your storedprocedures-> right click on it -> Function import -> and choose complex type.
then you can call it from your controller.
SabirB 21-Apr-11 11:17am
Thank you very much.i ll follow the way you described.
SabirB 28-Apr-11 6:51am
Now i got my storedprocedure and now i need to bind with a dropdownlist in one of my .aspx page.

and i did the coding like added a view but after i got this error.

The model item passed into the dictionary is of type 'System.Data.Objects.ObjectResult`1[SIMSaverMVC2.Models.getSalesRep_Result]', but this dictionary requires a model item of type 'SIMSaverMVC2.Models.getSalesRep_Result'.

Please let me know Urgent.

Herfst 28-Apr-11 7:29am
how did you bind it exactly after you called your stored procedure??
Herfst 28-Apr-11 7:35am
or do you have a code sample of your controller?
SabirB 28-Apr-11 7:49am
public ActionResult getSalesRepDetails()
objTelestreamProductionDBEntities = new TelestreamProductionDBEntities();
var salesReps = objTelestreamProductionDBEntities.getSalesRep();
return View(salesReps);

i have this Action result and from here i have created a view called getSalesDetails.

now i have one dropdown control in this view and i want to bind all the sales rep return by stored procedure to the drop down.
Herfst 28-Apr-11 7:53am
where did you got an error in your controller or view? and does your stored procedure have Parameters?
SabirB 28-Apr-11 8:02am
ok on this code i have not yet bind the dropdown only i am trying to initiate my view and there i am getting error.
and my SP doesn't have any parameter.
Herfst 28-Apr-11 8:10am
I have done this before but can't find the right example from where i learned it.
But look at this one / /
or this
Rate this: bad
Please Sign up or sign in to vote.

Solution 3


This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Cookies | Terms of Service
Web01-2016 | 2.8.180615.1 | Last Updated 11 Jan 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved.
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100