// 处理日期属性 public ActionResult ProcessDateProperty() { // 日期格式化选项 string dateTimeFormat = "MM/dd/yyyy"; // 获取当前日期 string currentDate = DateTime.Now.ToString(dateTimeFormat); // 将日期属性转换为字符串类型 string dateProperty = currentDate.ToString(dateTimeFormat); // 将日期属性添加到ViewModel中 ViewModel.DateProperty = dateProperty;
return View("YourView", ViewModel);
}
@model YourViewModel
@Html.TextBoxFor(m => m.DateProperty, new { @class = "datepicker" })
以上解决方案确保日期属性以字符串类型进行管理,并使用jQuery UI日期选择器显示日期。