我有以下剃刀代码:
<div class="container">
@Html.ValidationSummary(false)
@using (Html.BeginForm("EncryptFile", "Encryption", new { returnUrl = Request.Url.AbsoluteUri }, FormMethod.Post, new { @id = "encryptionform", @class = "form-horizontal" }))
{
<div class="form-group">
@Html.Label("File", new { @class = "control-label col-md-2" })
<div class="col-md-10">
<input type="file" id="encryptfilefield" name="uploadedfile" enctype='multipart/form-data'/>
</div>
</div>
<button type="submit" id="encryptfilebutton">Encrypt</button>
<button id="decryptfilebutton" type="button">Decrypt</button>
<button id="reencryptfilebutton" type="button">Re-Encrypt</button>
}
</div>
Run Code Online (Sandbox Code Playgroud)
当我单击“加密”按钮时,将调用以下控制器代码:
[HttpPost]
public ActionResult EncryptFile(string uploadedfile)
{
/*process the file without uploading*/
return Json(new { status = "success", message = "Encrypted!" });
}
Run Code Online (Sandbox Code Playgroud)
当我单击加密按钮时,我可以执行此操作,但uploadedfile字符串始终以 …
我需要使用带有RAZOR的MVC3将多个文件上传到Web服务器.我有以下代码.在控制器中,我的文件数为零.如何更正它以获取上传的文件的实际数量并获取内容?
public class MyFileController : Controller
{
public ActionResult MyFileProcessActionTest()
{
return View();
}
[HttpPost]
public ActionResult MyFileProcessActionTest(IEnumerable<System.Web.HttpPostedFileBase> files)
{
int fileCount = files.Count<System.Web.HttpPostedFileBase>();
return RedirectToAction("Index");
}
}
Run Code Online (Sandbox Code Playgroud)
视图
@{
ViewBag.Title = "MyFileProcessActionTest";
}
<h2>MyFileProcessActionTest</h2>
@using (Html.BeginForm())
{
<input type="file" name="files" id="file1" />
<input type="file" name="files" id="file2" />
<input type="submit" />
}
Run Code Online (Sandbox Code Playgroud)
读: