Saturday, 5 July 2014

How to Use jQuery Calender In MVC3 | jQuery UI Datepicker Calender Control In Asp.Net Mvc Application

7/05/2014 - By Pranav Singh 0

In this article I will show you how you can display jquery calendar control in your asp.net mvc application and retrieje the selected date at your controller .


So for this article first we will create a new mvcapplication and in this we will create model class file.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DateTimePickerUsingJquery.Models
{
    public class DateModel
    {
        public string SelectedDate { get; set; }
    }
}

After creating model we will create controller and add the below code in our controller.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DateTimePickerUsingJquery.Models;

namespace DateTimePickerUsingJquery.Controllers
{
    public class HomeController : Controller
    {
        //
        // GET: /Home/

        public ActionResult Index()
        {
            DateModel objdatemodel = new DateModel();
            objdatemodel.SelectedDate = "";
            return View(objdatemodel);
        }
        [HttpPost]
        public ActionResult Index(DateModel objdatemodel)
        {
            ViewBag.Date = objdatemodel.SelectedDate;
            return View(objdatemodel);
        }
    }
}

In this I have shown get and post both methods. Now we will create view for the controller action.

@model DateTimePickerUsingJquery.Models.DateModel
@{
    ViewBag.Title = "jQuery UI Datepicker Calender Control In Asp.Net Mvc Application";
}
<link rel="stylesheet" href="http://code.jquery.com/ui/1.11.0/themes/smoothness/jquery-ui.css">
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script src="http://code.jquery.com/ui/1.11.0/jquery-ui.js"></script>
<h2>
    Datepicker Calender</h2>
<script>
    $(function () {
        $("#txtdatepicker").datepicker();
    });
</script>
@using (Html.BeginForm("Index", "Home"))
{
    <p>
        Date: @Html.TextBoxFor(m => m.SelectedDate, new { @id = "txtdatepicker", @style = "width:150px;" })</p>
    <input type="submit" value="Submit" />
    if (ViewBag.Date != null)
    {
    <p>
        Your Selected Date :@ViewBag.Date</p>
    }
}

Below mention jQuery code used for displaying the jQuery calendar.

<script>
    $(function () {
        $("#txtdatepicker").datepicker();
    });
</script>

Now we have done run the page to see the output.



DOWNLOAD

About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Global Classified : Connectseekers.com
© 2014 aspdotnet-pools.com Designed by Bloggertheme9.
back to top