我的视图模型为
public class StudViewModel
{
public StudLineViewModel()
{
StudLine = new List<CreateReqLineViewModel>();
}
public StudheaderViewModel StudHeader { get; set; }
public List<StudLineViewModel> StudLine { get; set; }
}
public class StudheaderViewModel
{
public int Roll_no { get; set; }
public DateTime? birthday_date { get; set; }
}
public class StudLineViewModel
{
public int Sub_Id { get; set; }
public double marks { get; set; }
}
var MainVMObj = new StudViewModel();
var StudHeaderObj = new StudheaderViewModel ();
StudHeaderObj.Roll_no =1;
StudHeaderObj.birthday_date =null;
MainVMObj.StudHeader = StudHeaderObj ;
MainVMObj.StudLine =null;
return Partialview("StudInfo",MainVMObj );
视图中的代码
@Html.TextBoxFor(model => model.StudHeader.birthday_date ,new { @class = "InputText", onclick = "javascript:NewCssCal (this.Id,'ddMMMyyyy','arrow','','','','future')" })
预期结果
1.生日指定为空,但显示为默认日期,如01-Jan-0001。
我在
处被调试,发现问题
MainVMObj.StudHeader = StudHeaderObj ->将对象值分配为默认值。因此出生日期从null到默认(01-01-001)
请提供解决方案
编辑器给Ans不要编辑帖子