使用 MVC 4.0/Razor 作为视图引擎。
场景:将日历绑定到文本框,单击 txtBox 应该让日历向下流动,使用 jqueryUI 的 datepicker 并将其提交到 sql db。
我做了什么:
型号类:
public class UserModels
{
[Required(ErrorMessage = "Mandatory Field")]
public virtual string Name { get; set; }
public virtual int Id { get; set; }
[DataType(DataType.Date), DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public virtual DateTime Dob { get; set; }
[Display(Name = "CountrY")]
public virtual string Country { get; set; }
public virtual string Gender { get; set; }
}
剃刀视图:
@model EMSapp.Models.UserModels
@{
ViewBag.Title = "AddUser";
}
<h2>AddUser</h2>
<script src="../../Scripts/jquery-1.7.1.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.core.js" type="text/javascript"></script>
<script src="../../Scripts/jquery.ui.datepicker.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.10.2.custom.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function () {
$("#date").datepicker();
});
</script>
@using (Html.BeginForm()) {
@Html.ValidationSummary(true)
<fieldset>
<legend>UserModels</legend>
<div class="editor-label">
@Html.LabelFor(model => model.Dob)
</div>
<div class="editor-field">
@**Html.TextBoxFor(model => model.Dob, new { id = "date" })**
</div>
错误:何时加载视图,抛出“对象不支持此属性或方法”。