我在IIS Express上部署了ASP.NET MVC Web应用程序。我面临的问题是我的模型绑定返回null 仅在Internet Explorer上>]。
这种情况是,当用户不
上传文档时,SimpleObject.File.File
应该返回null
,但仅在IE上,SimpleObject.File
返回null,这破坏了我们的网站。这是我的代码的简化版:
模型
([SupportingFile
是HttpPostedFileBase
,SupportingFile.File
的包装类:
public class SimpleObject: IValidatableObject { [Required] [Display(Name = "SupportingFiles_Name", ResourceType = typeof(ValidationStrings))] public SupportingFile File { get; set; } public SimpleObject() { this.File = new SupportingFile(); } }
表单的一部分
<div class="form-row hide"> @Html.RequiredLabelFor(m => m.File.File,"Upload document",true) @Html.TextBoxFor(m => m.File.File, new {type="file"}) @Html.ValidationMessageFor(m => m.File.File) </div>
Controller
[AllowAnonymous] [HttpPost] [ValidateAntiForgeryToken] //CSRF validation public ActionResult Index(SimpleObject model) { if (model.File == null) { throw new Exception("There is a special place in hell for IE"); } }
有趣的是,我什至没有绑定
SimpleObject.File
-它是在默认构造函数中初始化的。我绑定的是SimpleObject.File.File
,除IE之外,所有其他浏览器(FF,Chrome)均按预期工作...
我在IIS Express上部署了ASP.NET MVC Web应用程序。我面临的问题是我的模型绑定仅在Internet Explorer上返回null。情况是,当用户不...
我知道这很旧,但是今天我遇到了这样的问题,不能在IE上工作的原因是因为我的输入字段被禁用,我将其更改为只读,没有问题地工作了