查询功能 这个小Demo引用了Bootstrap样式

添加用了模态框

显示

分页
Controller控制器
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Model;
using BLL;
using Newtonsoft.Json;
namespace WebApplication1.Controllers
{
public class HomeController : Controller
{
UsBLL bll = new UsBLL();
// GET: Home
public ActionResult Index(int pageindex = 1, string name = "")
{
int pagesize = 3, count;
if (name == "")
{
ViewBag.list = bll.SelAllShow(pageindex, pagesize, out count, "");
ViewBag.name = name;
ViewBag.pageindex = pageindex;
ViewBag.count = count / pagesize + (count % pagesize == 0 ? 0 : 1);
}
else
{
ViewBag.list = bll.SelAllShow(pageindex, pagesize, out count, name);
ViewBag.name = name;
ViewBag.pageindex = pageindex;
ViewBag.count = count / pagesize + (count % pagesize == 0 ? 0 : 1);
}
return View();
}
public ActionResult addDo(Us m, HttpPostedFileBase file)
{
if (file == null)
{
return Content("<script>alert(‘请重新选择上传文件!‘);location.href=‘/Home/Index‘;</script>");
}
string path = Request.MapPath("/img/") + System.IO.Path.GetFileName(file.FileName);
file.SaveAs(path);
m.Upicture = "/img/" + System.IO.Path.GetFileName(file.FileName);
if (bll.Add(m)>0)
{
return Content("<script>alert(‘添加成功!‘);location.href=‘/Home/Index‘;</script>");
}
else
{
return Content("<script>alert(‘添加失败!‘);location.href=‘/Home/Index‘;</script>");
}
}
/// <summary>
/// 删除方法
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public ActionResult Del(int id)
{
if (bll.Del(id)>0)
{
return Content("<script>alert(‘删除成功!‘);location.href=‘/Home/Index‘;</script>");
}
else
{
return Content("<script>alert(‘删除失败!‘);location.href=‘/Home/Index‘;</script>");
}
}
}
}