如何防止Model for Datetime对象的默认验证 [英] how to prevent default validation of Model for Datetime object
问题描述
HI好友,我有一个模型,其中日期时间验证自动完成?我需要阻止它。当我将值发布到服务器时,我需要为日期时间发布空值如何执行。我的第二个问题是我的桌子的CSS样式和复选框没有调用代码:
MasterModel.cs
公共类Gema_Doctor:IDisposable
{
[必填]
[显示(姓名=DoctorId)]
public int Dr_Id {得到;组; }
[必填]
[显示(名称=公司代码)]
public int CompanyCode {get;组; }
[必填]
[显示(名称=Dr_Name)]
公共字符串Dr_Name {get;组; }
[显示(名称=Dr_DOB)]
public DateTime Dr_DOB {get;组; }
}
查看页面是
@ Html.LabelFor(M => Model.Doctor.Dr_Add2 )
@ Html.TextBoxFor(M => Model.Doctor.Dr_Add2)
@ Html.LabelFor(M => Model.Doctor.Dr_City)
@ Html.TextBoxFor(M => Model.Doctor.Dr_City)
@ Html.LabelFor(M => Model.Doctor.Dr_DOB)
@ Html.TextBoxFor(M => Model.Doctor.Dr_DOB)
@ Html.LabelFor(M => Model.Doctor.Dr_Phone)
@ Html.TextBoxFor(M => Model.Doctor.Dr_Phone)
我的css不工作是
HI Friends, I am having a Model in which the date time validation is done automatically? I need to prevent it. When I am posting values to the server I need to post null values for date time how to do it. And my second question is css style for my table and checkbox is not getting called Code:
MasterModel.cs
public class Gema_Doctor : IDisposable
{
[Required]
[Display(Name= "DoctorId")]
public int Dr_Id { get; set; }
[Required]
[Display(Name = "CompanyCode")]
public int CompanyCode { get; set; }
[Required]
[Display(Name = "Dr_Name")]
public string Dr_Name { get; set; }
[Display(Name = "Dr_DOB")]
public DateTime Dr_DOB { get; set; }
}
viewpage is
@Html.LabelFor(M => Model.Doctor.Dr_Add2)
@Html.TextBoxFor(M => Model.Doctor.Dr_Add2)
@Html.LabelFor(M => Model.Doctor.Dr_City)
@Html.TextBoxFor(M => Model.Doctor.Dr_City)
@Html.LabelFor(M => Model.Doctor.Dr_DOB)
@Html.TextBoxFor(M => Model.Doctor.Dr_DOB)
@Html.LabelFor(M => Model.Doctor.Dr_Phone)
@Html.TextBoxFor(M => Model.Doctor.Dr_Phone)
And my css which is not working is
/* Checkbox For Week */
.checkboxforweek
{
}
.checkboxforweek label
{
display: inline;
}
/* Table For Doctor */
.doctortable
{
width: 100%;
}
.doctortable tr
{
width: 100%;
}
.doctortable td
{
width: 35%;
}
推荐答案
也许你可以这样做:
Maybe you could do that:
[Display(Name = "Dr_DOB")]
public DateTime? Dr_DOB { get; set; }
这会使属性Dr_DOB可以为空。
This would make the property Dr_DOB nullable.
这篇关于如何防止Model for Datetime对象的默认验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!