0

使用 ASP .Net MVC 4 Razor。

在我的查看页面上,我有HTML

    <div>
        <input type="file" id="multiFile" class="multi" name="multiFile" accept="jpg|png|gif|xls|xlsx|doc"/>
    </div>

我正在使用以下脚本

<script src="http://jquery-multifile-plugin.googlecode.com/svn/trunk/jquery.js" 
type="text/javascript"></script>
<script src="http://jquery-multifile-plugin.googlecode.com/svn/trunk/jquery.MultiFile.js" 
type="text/javascript"></script>

在我的控制器中,[HTTPPost]方法:

        [HttpPost]
        public ActionResult Index(SampleModel model)
        {
            if(Request.Files.Count>0)
                HttpPostedFileBase uploads = Request.Files[0];

          //More codes here with model.............................
        }

我正在关注Multiple File Uploadcodeproject的教程。并面临. **错误是:嵌入式语句不能是声明或标记语句HttpPostedFileBase

4

1 回答 1

0

我使用的 Html(仅添加了multiple="multiple"

<div>
    <input type="file" multiple="multiple" id="multiFile" class="multi" name="multiFile" accept="jpg|png|gif|xls|xlsx|doc"/>
</div>

在我的控制器中:

[HttpPost]
    public ActionResult Index(SampleModel model)
    {

        string fileName1 = "";
        HttpPostedFileBase uploads ;

        if (Request.Files.Count > 0)
        {
            for (int i = 0; i < Request.Files.Count; i++)
            {
                //uploads[i] = new HttpPostedFileBase();
                uploads = Request.Files[i];
                fileName1 = Path.GetFileName(uploads.FileName);
                uploads.SaveAs(Server.MapPath(fileName1));
            }
        }

我已经上传了所有文件!!!!

于 2014-03-13T14:09:42.790 回答