asp.net-mvc - ASP.NET MVC3 客户端验证的奇怪问题

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

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

我的 View 基于我创建的 View 模型,其中以下字段为必填

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

此下拉列表从 Controller 传递一个空的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>

如果有人能为我阐明这一点,我将非常感激。

最佳答案

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

公共(public)整数?子状态ID;

关于asp.net-mvc - ASP.NET MVC3 客户端验证的奇怪问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7081912/

相关文章:

asp.net-mvc - 将 Glimpse 添加到引用 EF 项目的 MVC 项目的正确方法是什么?

c# - ASP.NET MVC 的新手,在处理包含表单的呈现操作时遇到问题

c# - “BeginContext”在应用程序启动时的当前上下文错误中不存在

c# - 空白在 Razor View C# 中转换为 null

c# - 如何将部分 View 呈现为字符串?

asp.net-mvc - 为我的 MVC 应用程序创建服务层?

asp.net - 请求重定向到/Account/Login?ReturnUrl=%2f,因为服务器上安装了 MVC 3

c# - 关于验证显示 2 个表单的页面的建议

Javascript 验证 - 与服务器同步

javascript - 尝试使用 formvalidator.net 为 "alpha"编写自定义验证器?