----我的控制器-
public ActionResult Edit(int id)
{
var dbContext = new MyDBDataContext();
var userDetails = dbContext.Users.FirstOrDefault(userId => userId.UserId == id);
var user = new Management.Models.User();
if (userDetails != null)
{
user.DOB = Convert.ToDateTime(userDetails.DOB);
user.POS = Convert.ToDateTime( userDetails.POS);
}
return View(user);
}
- - -模型 - - -
[Required(ErrorMessage = "Please Enter the Date that Start service")]
[Display(Name = "Period Of Service")]
//[DisplayFormat(DataFormatString = "{dd-mm-yyyy}", ApplyFormatInEditMode = true)]
[DataType(DataType.Date)]
public DateTime POS { get; set; }
[Required(ErrorMessage = "Please Select the Date of birth")]
[Display(Name = "Date of birth")]
//[DisplayFormat(DataFormatString = "{dd-mm-yyyy}", ApplyFormatInEditMode = true)]
[DataType(DataType.Date)]
public DateTime DOB { get; set; }
- - - - -看法 - - - -
<div class="editor-label">
@Html.DisplayName("Date Of Join")
</div>
<div class="editor-field">
@Html.EditorFor(model => model.POS)
@Html.ValidationMessageFor(model => model.POS)
</div>
<div class="editor-label">
@Html.LabelFor(model => model.Salary)
</div>
如果您EditorFor
用于生成浏览器日期选择器(HTML5),则(请注意格式字符串)
Required(ErrorMessage = "Please Enter the Date that Start service")]
[Display(Name = "Period Of Service")]
[DisplayFormat(DataFormatString = "{0:yyyy-MM-dd}", ApplyFormatInEditMode = true)]
[DataType(DataType.Date)]
public DateTime POS { get; set; }
然后,POS
将在浏览器的区域性中显示的值。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句