ASP.NET MVC3客户端验证的奇怪问题

时间:2011-08-16 16:55:51

标签: asp.net-mvc asp.net-mvc-3 validation

我遇到ASP.NET MVC3客户端验证问题。

我的观点基于我使用以下字段创建的视图模型Required

public class AppointmentFeedbackViewModel_Validation
{

    [Required]
    public string AttendeeName { get; set; }

    [Required(ErrorMessage = "Notes must be filled in")]
    public string Notes { get; set; }

    [Required(ErrorMessage = "Appointment status must be filled in")]
    public int AppointmentStatusId { get; set; }

    [Required]
    public int StarId { get; set; }

}

不幸的是,提交表单时会出现完全不相关的字段SubStatusId

此下拉列表从控制器传递空List

new List<EF.ViewModels.OpportunityConnectTypeViewModel>();

并标记如下

<div class="display-label-styled">
    Please select another reason for this outcome
</div>
<div class="display-field-styled">
    @Html.DropDownListFor(model => model.SubStatusId, new SelectList(ViewBag.SubStatus, "ID", "StatusName"))
    @Html.ValidationMessageFor(model => model.SubStatusId)
</div>

如果有人能为我阐明这一点,我真的很感激。

1 个答案:

答案 0 :(得分:4)

SubStatusId是int吗? Int是隐式要求的。如果您不需要它,请将其声明为可为空的int:

public int? SubStatusId;