簡體   English   中英

ASP.NET MVC 模型綁定僅在 Internet Explorer 上返回 null

[英]ASP.NET MVC model binding returns null ONLY on Internet Explorer

我在 IIS Express 上部署了一個 ASP.NET MVC Web 應用程序。 我面臨的問題是我的模型綁定僅在 Internet Explorer 上返回 null 。

場景是當用戶上傳文檔時, SimpleObject.File.File應該返回null ,但只有在 IE 上, SimpleObject.File返回 null ,這破壞了我們的網站。

這是我的代碼的簡化版本:

型號

SupportingFileHttpPostedFileBaseSupportingFile.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>

控制器

[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 - 它是在默認構造函數中初始化的。 我綁定的是SimpleObject.File.File ,所有其他瀏覽器(FF,Chrome)都按預期工作,除了 IE ...

我知道這是舊的,但我今天遇到了這樣的問題,無法在 IE 上工作的原因是因為我的輸入字段被禁用,我將其更改為只讀,沒有問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM