Example #1
0
        //展示下载文档页面
        public ActionResult Document()
        {
            BamnContext b    = new BamnContext();
            var         list = repositiory.GetSelect <Doc, int>(m => true, m => m.ID).ToList();

            ViewBag.list = list;
            return(View());
        }
Example #2
0
        //搜索界面
        public ActionResult Search()
        {
            BamnContext b         = new BamnContext();
            string      key       = "";
            var         modellist = b.Article.Where(m => m.Title.Contains(key)).ToList();

            ViewBag.ArticleList = modellist;
            return(View());
        }
Example #3
0
 protected void Application_Start()
 {
     AreaRegistration.RegisterAllAreas();
     FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
     RouteConfig.RegisterRoutes(RouteTable.Routes);
     BundleConfig.RegisterBundles(BundleTable.Bundles);
     //初始化数据库
     Database.SetInitializer(new CreateDatabaseIfNotExists <BamnContext>());
     using (var bamnContext = new BamnContext())
     {
         //如果不存在数据库则创建
         bamnContext.Database.Initialize(true);
     }
 }
Example #4
0
        public ActionResult SearchResult(string key)
        {
            BamnContext b         = new BamnContext();
            var         modellist = b.Article.Where(m => m.Title.Contains(key)).ToList();

            if (modellist.Count == 0)
            {
                return(Content("你所搜索内容不存在!"));
            }
            else
            {
                ViewBag.ArticleList = modellist;
                return(View());
            }
        }
        public ActionResult Upload(FormCollection form)
        {
            if (Request.Files.Count == 0)
            {
                //Request.Files.Count 文件数为0上传不成功
                return(View());
            }
            var file = Request.Files[0];

            if (file.ContentLength == 0)
            {
                //文件大小大(以字节为单位)为0时,做一些操作
                return(View());
            }
            else
            {
                //文件大小不为0
                file = Request.Files[0];
                //保存成自己的文件全路径,newfile就是你上传后保存的文件,
                //服务器上的UpLoadFile文件夹必须有读写权限
                //取得目标文件夹的路径
                string target = Server.MapPath("/") + ("/Files/");
                //取得文件名字
                string filename = file.FileName;
                //获取存储的目标地址
                string path = target + filename;
                file.SaveAs(path);
                //对此文件信息存到数据库
                Doc doc = new Doc {
                    Name = filename, Path = target
                };
                BamnContext b = new BamnContext();
                b.Doc.Add(doc);
                b.SaveChanges();
            }
            return(RedirectToAction("Document", "Home"));
        }