C# MVC上传多个文件
正如您在我的图表中所看到的,每个C# MVC上传多个文件,c#,asp.net-mvc,file-upload,C#,Asp.net Mvc,File Upload,正如您在我的图表中所看到的,每个Post可以有多个positmages 如何在ASP.NET MVC中上载图像?我不知道每篇文章可以有多少张图片,所以我不喜欢我的方法: <label for="file1">Filename:</label> <input type="file" name="files" id="file1" /> <label for="file2">Filename:</label> <input
Post
可以有多个positmage
s
如何在ASP.NET MVC中上载图像?我不知道每篇文章可以有多少张图片,所以我不喜欢我的方法:
<label for="file1">Filename:</label>
<input type="file" name="files" id="file1" />
<label for="file2">Filename:</label>
<input type="file" name="files" id="file2" />
文件名:
文件名:
在我上传了一张图片之后,我想对图片进行预览
这就是我目前所拥有的
@using (Html.BeginForm("Edit", "BlogPost", FormMethod.Post, new { nctype="multipart/form-data" }))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
<fieldset>
<legend>Post</legend>
@Html.HiddenFor(model => model.ID)
<div class="editor-label">
@Html.LabelFor(model => model.Title)
</div>
<div class="editor-field">
@Html.EditorFor(model => model.Title)
@Html.ValidationMessageFor(model => model.Title)
</div>
<label for="file1">Filename:</label>
<input type="file" name="files" id="file1" />
<label for="file2">Filename:</label>
<input type="file" name="files" id="file2" />
<input type="submit" />
<p>
<input type="submit" value="Save" />
</p>
</fieldset>
@使用(Html.BeginForm(“Edit”、“BlogPost”、FormMethod.Post、new{nctype=“multipart/formdata”}))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
邮递
@Html.HiddenFor(model=>model.ID)
@LabelFor(model=>model.Title)
@EditorFor(model=>model.Title)
@Html.ValidationMessageFor(model=>model.Title)
文件名:
文件名:
控制器:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(Post post, int[] selectedCategories, IEnumerable<HttpPostedFileBase> files)
{
if (ModelState.IsValid)
{
//Code to Edit
}
}
[HttpPost]
[ValidateAntiForgeryToken]
公共操作结果编辑(Post Post、int[]selectedCategories、IEnumerable文件)
{
if(ModelState.IsValid)
{
//要编辑的代码
}
}
使用BlueImp jQuery文件上传器解决方案:
它规定:
。多文件选择、拖放支持、进度条、验证和预览图像
使用此解决方案此解决方案没有预览图像。问题似乎是关于C#和ASP.NET的,我不确定jQuery在这方面有何帮助。我已经多次将其用作大型C#ASP.NET MVC应用程序的文件上载器组件。“MVC”与上载图像和呈现预览无关,而预览是OP的实际需求。