Skip to content

Calendar code in a View

Pell Xaba

Asked Aug 13, 2013, 2:36 PM EDT2 answers
Share
LinkedInX
i want a calender that has text box, created in mvc4 razor in a view

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • Sunny  Sharma
    0
    Hi Pell Xaba,

    Do you want a text box inside Calender or a Calender on TextBox Click or hover or etc...? please clarify.

    Thanks.
    0
  • Sunny  Sharma
    0
    if you just want a Calender in a text box, then you have two ways in MVC4. Either you go with HTML5 date type input or you use some jQuery plugin.

    Follow the code below if you want so:
    ----------------------------------------------------------------------
    @{  Layout = null; }

    <!Doctype html>

       <html lang="en" >
          <head>  <title>   Sample Date picker in MVC4 Razor view  </title>
             <link href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css"; rel="stylesheet" />

            <script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.js";></script>
            <script type="text/javascript" src="http://code.jquery.com/ui/1.10.3/jquery-ui.js";></script>
            
    <script >  
                 $(document).ready(
    function () {  
                     $(
    "#txtDate").datepicker({dateFormat:"yy-mm-dd"});  });  
            </script>
       </head>
       <body>  
        @Html.Label("jQuery DatePicker")  
        @Html.TextBox("txtDate")  
        @Html.Label("HTML5 DatePicker");  
        <input type="date" id="txtDate2" />
        </body>

    </html>



    -------------------------------------------------------------------------------------


    Hope it helps :)
    0