Click here to Skip to main content
15,912,072 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have fetched data from datatable using stored procedure. Now I don't know how to bind them into HTML controls in my view. I am using MVC framework. Here is my code from where I am calling web service.
$('#btnSearch').click(function () {
           alert('in search function');
           $.ajax({
               type: "POST",
               url: location.pathname + "SearchFromHome.asmx/SearchFromHomeBus",
               data: "{fromid:'" + 1 + "' , toid:'" + 2 + "'}",
               dataType: "json",
               contentType: "application/json; charset=utf-8",
               success: SearchSuccess,
               error: SearchError
           });

Here is my web method :
C#
public IEnumerable<CitySearchResult>  SearchFromHomeBus(int fromid, int toid)
       {
          // DbDataReader sqlreader;
           SqlParameter []para=new SqlParameter[2];
           para[0]=new SqlParameter("@city1",fromid);
           para[1]=new SqlParameter("@city2",toid);
           using (cab_4_21Entities1 d = new cab_4_21Entities1())

           {
               ObjectResult<CitySearchResult> search =d.ExecuteStoreQuery<CitySearchResult>("usp_SearchcabResult @city1, @city2", para);
               //List<CitySearchResult> search = (d.ExecuteStoreQuery<CitySearchResult>("usp_SearchcabResult", para)).ToList<CitySearchResult>();
               List<CitySearchResult> searchResult=search.ToList<CitySearchResult>();

               return searchResult;
           }
       }

In this web method I have used entity framework. But I don't want to use it further because I am not comfortable with it. So, if I use stored procedure and store retrieved data into datatable, How to bind that data into HTML controls in the view?
Posted
Comments
Sascha Lefèvre 7-Apr-15 20:11pm    
If I interprete your question correctly, your problem is how to convert a DataTable into a IEnumerable<CitySearchResult> ?

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900