【问题标题】:upload file without refreshing the whole page in mvc razor上传文件而不刷新mvc razor中的整个页面
【发布时间】:2013-03-14 15:55:00
【问题描述】:

我正在开发 MVC 3 Razor。如何在不刷新整个页面的情况下上传文件。我下面提到的代码

@using (Html.BeginForm())
    {
        <input type='file' name='file' id='file' />
        <input type="Button" value="upload" />
    }

我的问题是我无法在上述 Html.BeginForm() 中定义动作和控制器。 所以当我点击上传按钮时,它会转到控制器的操作。如何将我上传的文件从视图传递到控制器。请帮助。如果有任何演示样本可用,让我根据我的场景分享。

【问题讨论】:

    标签: razor


    【解决方案1】:

    检查此代码,

    @using (Html.BeginForm("FileUploadss", "Controller", FormMethod.Post, 
                                      new {enctype ="multipart/form-data"})) 
    { 
            <input type='file' name='file' id='file' />
            <input type="submit" value="upload" />
    }
    

    转到你的控制器并使用此代码,

     public ActionResult FileUploadss(HttpPostedFileBase file)
        {
           if(file.ContentLength>0)
                {
                }
        } 
    

    【讨论】:

      猜你喜欢
      • 2011-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-23
      • 1970-01-01
      • 1970-01-01
      • 2018-08-20
      • 1970-01-01
      相关资源
      最近更新 更多