JsonResult json = new JsonResult();
json.Data = new
{
result = "true"
};
return json;
}
///
/// 删除学生信息
///
/// <param name="no">
///
public ActionResult DeleteStudent(string no)
{
bool IsDelete= _Student.Delete(no);
JsonResult json = new JsonResult();
return json;
if (IsDelete)
{
json.Data = new
{
result = "true"
};
}
else
{
json.Data = new
{
result ="false"
};
}
return json;
}
///
/// 添加学生信息
///
/// <param name="no">
/// <param name="name">
/// <param name="sex">
/// <param name="birsthday">
/// <param name="sclass">
///
public ActionResult AddStudent(string no,string sclass)
{
MvcExamples.Model.Student _student = new MvcExamples.Model.Student();
_student.sno = no;
_student.sname = name;
_student.ssex = sex;
_student.sbirthday = Convert.ToDateTime(birsthday);
_student.sclass = sclass;
_Student.Add(_student);
JsonResult json = new JsonResult();
json.Data = new
{
result = "true"
};
return json;
}
///
/// 提供弹出窗口的数据
///
/// <param name="id">
///
public ActionResult WindowData(int id)
{
JsonResult json = new JsonResult();
//这里给json数据(这里只是演示,下面数据是模拟的)
json.Data = new
{
name = "张三",sex = "男"
};
return json;
}
}
}
4、两个分页辅助类PagedList和MikePagerHtmlExtensions
PagedList辅助类
namespace System.Web.Mvc
{
public interface IPagedList
{
int TotalPage //总页数
{
get;
}
int TotalCount
{
get;
set;
}
int PageIndex
{
get;
set;
}
int PageSize
{
get;
set;
}
bool IsPreviousPage
{
get;
}
bool IsNextPage
{
get;
}
}
public class PagedList : List,IPagedList
{
public PagedList(IQueryable source,int? index,int? pageSize)
{
if (index == null) { index = 1; }
if (pageSize == null) { pageSize = 10; }
this.TotalCount = source.Count();
this.PageSize = pageSize.Value;
this.PageIndex = index.Value;
this.AddRange(source.Skip((index.Value - 1) * pageSize.Value).Take(pageSize.Value));
}
public int TotalPage
{
get { return (int)System.Math.Ceiling((double)TotalCount / PageSize); }
}
public int TotalCount
{
get;
set;
}
///
///
///
public int PageIndex
{
get;
set;
}
public int PageSize
{
get;
set;
}
public bool IsPreviousPage
{
get
{
return (PageIndex > 1);
}
}
public bool IsNextPage
{
get
{
return ((PageIndex) * PageSize) < TotalCount;
}
}
}
public static class Pagination
{
public static PagedList ToPagedList(this IOrderedQueryable source,int? pageSize)
{
return new PagedList(source,index,pageSize);
}
public static PagedList ToPagedList(this IOrderedQueryable source,int? index)
{
return new PagedList(source,10);
}
public static PagedList ToPagedList(this IQueryable source,pageSize);
}
public static PagedList ToPagedList(this IQueryable source,10);
}
}
}
MikePagerHtmlExtensions辅助类
namespace System.Web.Mvc
{
public static class MikePagerHtmlExtensions
{