JQuery Date picker not working in view

439 Views Asked by At

i have the below code to get a date picker for a view, some how the below code is not working i am not sure where i am going wrong, could anyone help me to get the below needs 1. i should have a date picker and when the user submits i want to values selected by the user

@{
    ViewBag.Title = "Index";
}

<h4>Welcome @Session["LoginName"]</h4>
<h4>@ViewBag.LoginId</h4>

<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
     $(function () {
         $("#MyDate").datepicker();
     });
</script>
@using (Html.BeginForm("ValidateUser", "Login", FormMethod.Post))
{

<h3>Select Bussiness Date </h3>
<div>
    <input type="text" id="MyDate" />
</div>

<div class="form-group">
    <div class="col-md-offset-2 col-md-10">
        <input type="submit" value="Continue" class="btn btn-default" />
    </div>
</div>

}


<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
1

There are 1 best solutions below

0
Hasan Elsherbiny On

remove these lines from the begin of your view

<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
 $(function () {
     $("#MyDate").datepicker();
 });
</script>

and change the last lines like this

<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/jquery.validate.min.js"></script>
<script src="~/Scripts/jquery.validate.unobtrusive.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script>
     $(function () {
         $("#MyDate").datepicker();
     });
</script>

1-It's Better To Place Your Script Files at End Of Document

2-You Had Duplicated Jquery Files So You Get the Error