Html.ValidationMessageFor自定义消息始终显示

时间:2017-05-24 03:16:51

标签: asp.net-mvc

@Html.ValidationMessageFor(model => model.DeliverySchedule.d_date, "Please fill up.", new { @class = "text-danger" }) 我的验证。但它会继续显示页面加载。 在下面添加css之后。它在第一次加载时消失,但是当我提交带有空字段的表单时。消息没有出来。

.field-validation-valid
{display: none;}

Javascript ref还添加了

<script src="~/Scripts/jquery.validate.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>

控制器

 public ActionResult ArrangeDelivery() {
        var list = service.GetNotDeliveryScheduleList();
        return View(list);
    }
    [HttpPost]
    public ActionResult ArrangeDelivery(OrderViewModel model)
    {


        var result = service.SetDeliverySchedule(model);
        if (result==true)
        {
            return RedirectToAction("ArrangeDelivery");
        }
        var list = service.GetNotDeliveryScheduleList();
        return View(list);
    }

HTML

<div class='input-group date' id='datetimepicker2'>

                        @Html.EditorFor(model => model.DeliverySchedule.d_date, new { htmlAttributes = new { @class = "form-control bootdatepicker" } })
                        @Html.ValidationMessageFor(model => model.DeliverySchedule.d_date, "Please fill up.", new { @class = "text-danger" })

                        <span class="input-group-addon">
                            <span class="glyphicon glyphicon-calendar"></span>
                        </span>
                    </div>

查看模型

 public class OrderViewModel
{

    public OrderViewModel()
    {
        DeliveryScheduleList = new List<DeliverySchedule>();
        DeliveryPartList = new List<DeliveryPart>();
    }

    public List<DeliverySchedule> DeliveryScheduleList { get; set; }
    public DeliverySchedule DeliverySchedule { get; set; }
    public List<DeliveryPart> DeliveryPartList { get; set; }
}

数据库优先的实际模型

 public partial class DeliverySchedule
{
    public long ID { get; set; }
    public Nullable<long> DL_ID { get; set; }
    public Nullable<System.DateTime> datum { get; set; }
    public Nullable<System.DateTime> zeit { get; set; }
    public string customer_id { get; set; }
    public string customer { get; set; }
    public string area { get; set; }
    public string address_1 { get; set; }
    public string address_2 { get; set; }
    public string postal { get; set; }
    public string person_look_for { get; set; }
    public string contact_look_for { get; set; }
    public string PO_Number { get; set; }
    public string staff { get; set; }
    public string invoice { get; set; }
    public string service { get; set; }
    public string remarks { get; set; }
    public string d_type { get; set; }
    public string d_arranged { get; set; }
    public string i_return { get; set; }
    public string d_done { get; set; }
    public Nullable<System.DateTime> d_date { get; set; }
    public string d_time { get; set; }
    public string d_by { get; set; }
    public Nullable<int> DO_Number { get; set; }
}

0 个答案:

没有答案