Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC - jquery datepicker

Ok, so I'm new to ASP.NET MVC and JQuery.

I have followed the following example to the letter, and I'm not able to get the datepicker working:

http://codesprouts.com/post/Creating-A-DatePicker-Extension-In-ASPNet-MVC.aspx

Can anyone tell me if there are any ticks or gotchas with this?

Bernard.

like image 761
Bernard Avatar asked May 23 '09 08:05

Bernard


People also ask

How to add Datepicker in cshtml?

First, we need to link the CSS into our layout. Then, we link the JS file into our layout at the bottom line of code. After that, we try to assign the format of our input in class "datepicker". Then, we add another class in Add cshtml.


2 Answers

Use jquery hosted by google.

<script type="text/javascript" 
src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js">
</script>
<script type="text/javascript" 
src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.1/jquery-ui.min.js">
</script>

You will also need to link to your desired css.

$().ready(function()
{
    $('#from').datepicker({ dateFormat:'yy-mm-dd' });
});

<html>
...
<input id="from" class="date-field" name="from" type="text" >
like image 134
David Avatar answered Sep 29 '22 22:09

David


This blog post provides an excellent overview of integrating the jQuery datepicker into a MVC 3 site.

Some of other samples that I could find were focused on MVC1 and 2.

like image 44
John M Avatar answered Sep 29 '22 23:09

John M