在日期选择器中禁用日期

时间:2014-05-03 10:48:53

标签: asp.net-mvc asp.net-mvc-4 datepicker

我正在尝试在MVC4中创建一个约会页面。它运作良好,但我想禁用所选的日期。这是我的控制器预约:

public ActionResult Make()
       {
           return View();
       }
       [HttpPost]
       [ValidateAntiForgeryToken]
       public ActionResult Make(Models.AppModel User)
       {
           if (Session["UserEmail"] != null)
           {
               using (var db = new MaindbModelDataContext())
               {
                   var patient = db.Patients.FirstOrDefault(u => u.Email == (String)Session["UserEmail"]);

                   var app = new Appointment();

                   app.Date = (DateTime)User.Date;
                   app.Description = User.Description;
                   app.Status = "isPending";
                   app.PatientNo = patient.PatientNo;
                   app.AppNo = Guid.NewGuid().GetHashCode();
                   db.Appointments.InsertOnSubmit(app);
                   db.SubmitChanges();

               }
           }
           else
           {
               return RedirectToAction("Index", "User");
           }
           return RedirectToAction("Index", "Patient");
       }
       //
   }
}

这是我对datepicker的看法

@model DentAppSys.Models.AppModel
@{
    ViewBag.Title = "Appointment";
}
<link type="text/css" rel="stylesheet" href="//code.jquery.com/ui/1.10.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script>

@using (Html.BeginForm())
{
    @Html.AntiForgeryToken();
    @Html.ValidationSummary(true, "");
    <div>

        <fieldset>
            <legend>Get an Appointment</legend>


            <div>@Html.LabelFor(u => u.Date)</div>
            <div>
                @Html.TextBoxFor(u => u.Date, htmlAttributes: new { id = "DatePicker" })
                @Html.ValidationMessageFor(u => u.Date)

            </div>

            <div>@Html.LabelFor(u => u.Description)</div>
            <div>
                @Html.TextBoxFor(u => u.Description)

            </div>

            <input type="submit" value="Submit" class="footer_btn" />

        </fieldset>

    </div>
}
<script type="text/javascript">
    $(function () {
        $("#DatePicker").datepicker();
    });

</script>

1 个答案:

答案 0 :(得分:0)

尝试怎么样:

@Html.TextBoxFor(u => u.Date, htmlAttributes: new { id = "DatePicker", readonly = "readonly" })