MVC中的Service主要是用来处理数据交互的。
前端页面传递一个或者多个参数到Service的写法:
一个参数写法:
public DataTable 方法名 (Pagination pagination, string year) {
try
{
var strSql = new StringBuilder();
strSql.Append(@"select name from Student where name=@year");
var parameter = new List<DbParameter>();
parameter.Add(DbParameters.CreateDbParameter("@year", year));
return this.BaseRepository().FindTable(strSql.ToString(), parameter.ToArray());
}
catch
{
throw;
}
}
两个参数的写法:
public DataTable 方法名(Pagination pagination,string name, string age)
{
try
{
var strSql = new StringBuilder();
strSql.Append(string.Format(@"select name,age from Student where name={0} and age={1}", name, age));
return this.BaseRepository().FindTable(strSql.ToString());
}
catch
{
throw;
}
}