在零配置情况下,文件的上传文件夹是根目录下的Files文件夹,如何自定义文件的上传文件夹呢?
MVC文件上传相关兄弟篇:
□ 在web.config中配置
1:
2:
3: ...
4:
5:
6:
7:
8:
9:
10:
11:
Version可以通过右键程序集属性中查到。
PublicKeyToken可以通过反编译器,比如Reflector查到。
□ 注销BackloadDemoController的Index方法
1: using System.Web.Mvc;
2:
3: namespace MvcApplication6.Controllers
4: {
5: public class BackloadDemoController : Controller
6: {
7: // GET: /BackupDemo/
8: //public ActionResult Index()
9: //{
10: // return View();
11: //}
12: }
13: }
14:
□ 让BaseController继承BackloadDemoController,并注销Index方法
1: using System.Web.Mvc;
2:
3: namespace MvcApplication6.Controllers
4: {
5: public class BaseController : BackloadDemoController
6: {
7: //public ActionResult Index()
8: //{
9: // return View();
10: //}
11: }
12: }
□ 让HomeController继承BaseController
1: using System.Web.Mvc;
2:
3: namespace MvcApplication6.Controllers
4: {
5: public class HomeController : BaseController
6: {
7: public ActionResult Index()
8: {
9: return View();
10: }
11: }
12: }
13:
1:
2:
3:
4:
5:
6:@ViewBag.Title
7: @Styles.Render("~/Content/css")
8: @Styles.Render("~/Content/themes/base/css")
9: @Styles.Render("~/bundles/fileupload/bootstrap/BasicPlusUI/css")
10: @Scripts.Render("~/bundles/modernizr")
11:
12:
13:
14: @RenderBody()
15:
16: @Scripts.Render("~/bundles/jquery")
17: @Scripts.Render("~/bundles/jqueryui")
18: @Scripts.Render("~/bundles/fileupload/bootstrap/BasicPlusUI/js")
19: @RenderSection("scripts", required: false)
20:
21:
22:
展开@{ ViewBag.Title = "Index"; Layout = "~/Views/Shared/_Layout.cshtml";}@section scripts{ }
□ 结果:
上传2个文件:
这次,图片上传到了Uploads文件夹:
Uploads文件夹有刚上传的2个文件:
□ 如果想让web.config配置文件相对“干净”,可以把与Backload相关的配置放到单独的一个配置文件
web.config中可以这样:
1:
2:
3: ...
4:
5:
6:
7:
8:
根目录下的Web.Backload.config可以这样:
1:
2:
3:
4:
参考资料:
※ Backload官网※ Backload例子※ nuget上的Backload※ jQuery File Upload官网
※ github上的jQuery File Upload介绍※ github上的jQuery File Upload源码※ 下载jQuery File Upload结合Backload的MVC案例