0

I am using jquery 2.1.0 and its been called in my _Layouy.cshtml page @Scripts.Render("~/bundles/jquery") i am trying to add datepicker to my view but i am getting an error 0x800a01b6 - JavaScript runtime error: Object doesn't support property or method 'datepicker'. Jquery 2.1.0 was predownloded when i created a new project but under script folder there is no jquery-ui folder. Can this be the problem? this is my view:

@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' });
});

tereško
  • 58,060
  • 25
  • 98
  • 150
  • The MVC framework usually installs with jquery and jquery-ui libraries. If you don't see them installed (check `Scripts` folder and `App_Start/BundleConfig.cs`) you can add them using Nuget. – Andrei V Mar 10 '14 at 09:41
  • i've installed jquery UI (combined library)- and inserted these lines in _Layout.cshtml ` @Scripts.Render("~/bundles/jquery") @Scripts.Render("~/bundles/jquery-ui");` still i am getting same error. do i have to add anything in `App_Start/BundleConfig.cs` after downloading jquery UI (combined library)?? –  Mar 10 '14 at 09:50
  • Yes, you need to add all the files in the bundles: script and style files. See [this question](http://stackoverflow.com/questions/20081328/how-to-add-jqueryui-library-in-mvc-5-project). It has all the information you need. – Andrei V Mar 10 '14 at 09:55

1 Answers1

0

Add jquery UI to the view.

@Scripts.Render("<your_jqueryui_path>")

in scripts section.

Or atleast the datepicker

HCJ
  • 529
  • 1
  • 6
  • 14
  • i've inserted this in my _Layout.cshtml page which serves as a master page. But still i am getting same error: These are the two files i have called ` @Scripts.Render("~/bundles/jquery") @Scripts.Render("~/bundles/jquery-ui");` –  Mar 10 '14 at 10:07
  • This is not the file path. This is the bundle's relative path. Check in your bundle.config in the App_Start folder, if this path includes the jqueryui file. Something like bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include( "~/Scripts/jquery-ui-1.10.4.js")); – HCJ Mar 10 '14 at 10:23
  • Try adding this code in @section Scripts { @Scripts.Render("http://code.jquery.com/ui/1.10.3/jquery-ui.js");} – HCJ Mar 10 '14 at 11:48