如何将数据表的数据绑定到html控件中 [英] How to bind the data of datatable into html controls
问题描述
我使用存储过程从datatable中获取数据。现在我不知道如何在我的视图中将它们绑定到HTML控件中。我正在使用MVC框架。以下是我调用Web服务的代码。
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 :
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;
}
}
在这个网络方法中,我使用了实体框架。但是我不想进一步使用它,因为我对它不满意。因此,如果我使用存储过程并将检索到的数据存储到数据表中,如何将该数据绑定到视图中的HTML控件?
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?
推荐答案
('#btnSearch')。 click(function(){
alert('in search function');
('#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,
成功:SearchSuccess,
错误:SearchError
});
.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 :
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;
}
}
在这个网络方法中,我使用了实体框架。但是我不想进一步使用它,因为我对它不满意。那么,如果我使用存储过程并将检索到的数据存储到数据表中,如何将该数据绑定到视图中的HTML控件?
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?
这篇关于如何将数据表的数据绑定到html控件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!