MVC3字段未在生产服务器上验证

时间:2011-09-12 18:20:26

标签: entity-framework asp.net-mvc-3 validation poco

我正在使用带有.net 4的EF + MVC3,我的表单上有一个上传字段,在我的开发服务器上,它按预期完美运行,但当我将它移动到我的生产服务器时,无论何时表单已发布我收到The value '' is invalid.验证错误,即使我提交了一张图片(我已经在FireBug中签入,并填写了该字段)。

在网上看,无论什么时候出现这种情况,似乎都是EF模型的设定者是非公开的。但事实并非如此,因为模型上的这个属性不会映射到数据库中的任何字段(我不直接使用EF Poco,我已经围绕它们制作了模型)。

我认为这可能是IIS的差异,因为我的开发服务器正在运行IIS7 .net4,而生产者运行的是IIS6 .net4。

有没有人对为什么会发生这种情况有任何想法?

型号:

public class AddBookModel {
    public AddBookModel () { }
    public AddBookModel(Book book) {
        Title = book.Title;
        Description = HttpUtility.HtmlDecode(book.Description);
        CoverExtension = book.CoverExtension;
    }

    [Required(ErrorMessage="This field cannot be blank")]
    [DataType(DataType.Html)]
    [Display(Name="Description:")]
    public string Description { get; set; }
    [Required(ErrorMessage="This field cannot be blank")]
    [MaxLength(50)]
    [Display(Name="Title:")]
    public string Title { get; set; }

    private string _CoverExtension = String.Empty;
    public string CoverExtension {
        get { return _CoverExtension; }
        private set { if (value != null) { _CoverExtension = value; } }
    }

    public virtual string CoverPath { get { return String.Empty; } }

    private HttpPostedFileBase _Image;
    public HttpPostedFileBase Image {
        get { return _Image; }
        set { _Image = value; CoverExtension = value.GetFileExtension(); }
    }
    public ResultStatuses ActionStatus { get; set; }
}

查看(相关位):

    <div class="field @if (ViewData.ModelState["Image"] != null && ViewData.ModelState["Image"].Errors.Count > 0) { <text>field-error</text>}">
        @Html.LabelFor(m => m.Image)
        @Html.Upload("Image")
        @Html.ValidationMessageFor(m => m.Image, null, new { @class="error-hint" })
    </div>

更新

我现在已经检查了我的工作场所的代码,该代码运行与生产服务器相同的IIS版本(我相信),除了将权限写入我正在尝试上传的文件系统之外,它还可以正常工作文件,但这不会与验证错误有关吗?

Html上传助手:

public static MvcHtmlString Upload(this HtmlHelper helper, string name) {
            string result = string.Format("<input type=\"file\" id=\"{0}\" name=\"{0}\" />", name);
            return MvcHtmlString.Create(result);
        }

1 个答案:

答案 0 :(得分:0)

IIS 6和IIS 7具有不同的文件上载限制。根据{{​​3}},IIS6上的默认上传大小限制为200kb,而在IIS7上,根据this,默认上传大小限制为30mb。也就是说,从第二个链接开始,如果这是你的实际问题,我会发现一个不同的错误(我现在无法测试)。

相关问题