日期选择器在MVC中不起作用

时间:2014-03-10 09:22:16

标签: c# asp.net-mvc datepicker jquery-ui-datepicker

我正在使用jquery 2.1.0并在我的_Layouy.cshtml页面@Scripts.Render("~/bundles/jquery")中调用它我正在尝试将datepicker添加到我的视图中,但是我收到错误0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'datepicker'。当我创建一个新项目但是在脚本文件夹下没有jquery-ui文件夹时,Jquery 2.1.0被预处理。这可能是问题吗?这是我的观点:

@model Movie.Models.MovieModel

@{
ViewBag.Title = "Add";
Layout = "~/Views/Shared/_Layout.cshtml";
@Scripts.Render("~/bundles/jquery-ui");
}

 <h2></h2>

@using (Html.BeginForm())
{
@Html.AntiForgeryToken()

<div class="form-horizontal">
    <h4>MovieModel</h4>
    <hr />

    @Html.ValidationSummary(true)
        <div class="form-group">
        @Html.LabelFor(model => model.DOB, new { @id = "news_date", @class = "control-      label col-md-2" })
        <div class="col-md-10">
            <p>Date:<input type="text" id="Dob" class="datefield" /></p>
            @Html.EditorFor(model => model.DOB)
            @Html.ValidationMessageFor(model => model.DOB)
        </div>
    </div>

@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
 }

<script>

$(document).ready(function () {
    $("#news_date").datepicker("option", "datepickerOptions", { firstDay: 1 });
    $("#news_date").datepicker({ dateFormat: 'dd/mm/yy' });
});

1 个答案:

答案 0 :(得分:0)

将jquery UI添加到视图中。

@Scripts.Render("<your_jqueryui_path>")

在脚本部分。

或至少datepicker

相关问题