Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET C#4.0 MVC
hello?? Smile | :) Confused | :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 asp.net 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
Herfst533
Edited 7-Mar-11 14:14pm
thatraja239.2K
v2
Comments
AlbinAbel at 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
Member 3851103 at 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.
 
Sabir,
Centurion,SouthAfrica.
Rate this: bad
good
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.
  Permalink  
Comments
Member 3851103 at 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.
7.in 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.
 
Thanks,
Sabir
Herfst at 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 at 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.
Member 3851103 at 21-Apr-11 11:17am
   
Thank you very much.i ll follow the way you described.
SabirB at 28-Apr-11 6:51am
   
Thanks,
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 at 28-Apr-11 7:29am
   
how did you bind it exactly after you called your stored procedure??
Herfst at 28-Apr-11 7:35am
   
or do you have a code sample of your controller?
SabirB at 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 at 28-Apr-11 7:53am
   
where did you got an error in your controller or view? and does your stored procedure have Parameters?
SabirB at 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 at 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 /http://odetocode.com/blogs/scott/archive/2010/01/18/drop-down-lists-and-asp-net-mvc.aspx /
or this
http://stackoverflow.com/questions/1178175/multiple-dynamically-populated-drop-down-lists
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 354
1 Richard MacCutchan 320
2 OriginalGriff 255
3 Vinay Mistry 168
4 Jared Sanow 145
0 Sergey Alexandrovich Kryukov 5,939
1 OriginalGriff 4,885
2 CPallini 2,473
3 Abhinav S 1,507
4 Richard MacCutchan 1,437


Advertise | Privacy | Mobile
Web02 | 2.8.140814.1 | Last Updated 11 Jan 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

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