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