enctype='multipart/form-data'HTML表单中的含义是什么?我们何时应该使用它?
我理解之间的关系HttpPostedFileBase,并HttpPostedFileWrapper为他们两个(即在单元测试/嘲讽)的,在需要方面.但是,为什么,当我在回报中设置断点时HttpPostedFileBase,它是否显示为HttpPostedFileWrapper?
此外,HttpPostedFileBase不实现ContentType属性.那么为什么当我的代码只引用时它返回一个值HttpPostedFileBase,而不是HttpPostedFileWrapper?这是什么样的诡计?

编辑#1:
感谢@ lawliet29的精彩回复.我按照建议书写了结构.
public sealed class MyHttpPostedFile
{
public string ContentType { get { return "123"; } }
}
public abstract class MyHttpPostedFileBase
{
}
public class MyHttpPostedFileWrapper : MyHttpPostedFileBase
{
private MyHttpPostedFile _myHttpPostedFile;
public MyHttpPostedFileWrapper(MyHttpPostedFile myHttpPostedFile) {
_myHttpPostedFile = myHttpPostedFile;
}
public string ContentType { get { return _myHttpPostedFile.ContentType; } }
}
Run Code Online (Sandbox Code Playgroud)
为了使其工作,我需要传递这样的参数:
GetFiles(new MyHttpPostedFileWrapper(new MyHttpPostedFile());
Run Code Online (Sandbox Code Playgroud)
这似乎是我质疑的诡计存在的地方..NET如何知道传递给它的字节是一个类型的类MyHttpPostedFile,它应该采用该对象并将其作为参数传递给我的构造函数?
编辑#2:
我没有意识到ASP.NET …
我有以下剃刀代码:
<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字符串始终以 …
我正在使用asp.net mvc-5上载文件,HttpPostedFileBase但我在选择图像后却显示HttpPostedFileBase为空
这是我的代码
<input type="file" title="search image" file-model="profileimage" id="allfilepath" name="file" />
<button type="submit" class="btn btn-primary col-sm-5">
<span class="glyphicon glyphicon-plus"></span>
</button>
Run Code Online (Sandbox Code Playgroud)
和我的控制器
[HttpPost]
public ActionResult insert(HttpPostedFileBase file, quotationcompany quotecomp)
{
var allowedExtensions = new[] {
".Jpg", ".png", ".jpg", "jpeg"
};
if (file == null)
{
ViewBag.message = "Please Select Image";
return View();
}
else {
ViewBag.message = "Image Uploaded Successfully";
return View();
}
}
Run Code Online (Sandbox Code Playgroud)
如果(文件== null)(在此行(
file)在我上载png图片后显示为null)
这段代码有什么问题?