Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# MVC razor文件上传_C#_Asp.net Mvc_Azure_Razor_File Upload - Fatal编程技术网

C# MVC razor文件上传

C# MVC razor文件上传,c#,asp.net-mvc,azure,razor,file-upload,C#,Asp.net Mvc,Azure,Razor,File Upload,MVC的想法确实是全新的,但我正在尝试从视图中获取一个要上载的文件,并将其传递给控制器,然后控制器将其上载到azure blob存储。但是,我无法获得用户选择实际传递给控制器的文件。我已经看到并尝试过这个答案,但没有成功 选择文件的“我的视图” @using (Html.BeginForm("FileView", "Shares", FormMethod.Post, new { enctype = "multipart/form-data" })) { @Html.AntiForg

MVC的想法确实是全新的,但我正在尝试从视图中获取一个要上载的文件,并将其传递给控制器,然后控制器将其上载到azure blob存储。但是,我无法获得用户选择实际传递给控制器的文件。我已经看到并尝试过这个答案,但没有成功

选择文件的“我的视图”

  @using (Html.BeginForm("FileView", "Shares", FormMethod.Post, new { enctype = "multipart/form-data" })) 

 {
  @Html.AntiForgeryToken()

<div class="form-horizontal">
    <h4>FileUploadModel</h4>
    <hr />
    @Html.ValidationSummary(true, "", new { @class = "text-danger" })
    <div class="form-group">
        @Html.LabelFor(model => model.numshares, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.numshares, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.numshares, "", new { @class = "text-danger" })
        </div>
    </div>

    <div class="form-group">
        @Html.LabelFor(model => model.minshares, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">
            @Html.EditorFor(model => model.minshares, new { htmlAttributes = new { @class = "form-control" } })
            @Html.ValidationMessageFor(model => model.minshares, "", new { @class = "text-danger" })
        </div>
    </div>
    <div class="form-group">
        @Html.LabelFor(model => model.file, htmlAttributes: new { @class = "control-label col-md-2" })
        <div class="col-md-10">

             <input type="file" name="file" id="file" />

        </div>
    </div>

我完全不知道它出了什么问题,所以任何帮助都将不胜感激谢谢

我认为您缺少提交所选文件的提交按钮,如

 using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
  @Html.ValidationSummary();
  <input type="file" name="file" id="fileToUpload" class="lifile" />
  <span class="field-validation-error" id="spanfile"></span>
  <input type="submit" value="Upload File" id="btnSubmit" />
  @ViewBag.Message
}
使用(Html.BeginForm(“Index”,“Home”,FormMethod.Post,new{enctype=“multipart/formdata”}))
{
@Html.ValidationSummary();
@查看包。留言
}

也显示您的表单,您是否有
enctype=multipart/form data
?您的html应该在表单中
 using (Html.BeginForm("Index", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
  @Html.ValidationSummary();
  <input type="file" name="file" id="fileToUpload" class="lifile" />
  <span class="field-validation-error" id="spanfile"></span>
  <input type="submit" value="Upload File" id="btnSubmit" />
  @ViewBag.Message
}