Hi yogesjoshi,
I have created a sample in MVC 2 you need to implement same in MVC 5.
Refer below sample code and modify it according to your need.
Model -> Date.cs
public class Date
{
public DateTime StartDate { get; set; }
public DateTime EndDate { get; set; }
}
Controller-> HomeController.cs
public class HomeController : Controller
{
public ActionResult Index()
{
Date dt = new Date();
dt.StartDate = DateTime.Now.AddMonths(2);
dt.EndDate = DateTime.Now.AddMonths(3);
return View(dt);
}
}
View -> Index.aspx
<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<_167261_RangeDateStartAndEnd.Models.Date>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Home Page
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript" src="http://cdn.jsdelivr.net/momentjs/latest/moment.min.js"></script>
<link rel="stylesheet" type="text/css" href="http://cdn.jsdelivr.net/bootstrap/3/css/bootstrap.css" />
<script type="text/javascript" src="http://cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.js"></script>
<link rel="stylesheet" type="text/css" href="http://cdn.jsdelivr.net/bootstrap.daterangepicker/2/daterangepicker.css" />
<script type="text/javascript">
$(function () {
$('#StartDate').daterangepicker({
singleDatePicker: true,
showDropdowns: true,
locale: { format: "MM/DD/YYYY" }
},
function (start, end, label) {
var selectedDate = start._d;
var endMDate = new Date(selectedDate.getFullYear(), selectedDate.getMonth() + 1, 0);
endMDate = (endMDate.getMonth() + 1) + '/' + endMDate.getDate() + '/' + endMDate.getFullYear();
$('#EndDate').daterangepicker({
singleDatePicker: true,
locale: { format: "MM/DD/YYYY" },
startDate: endMDate
});
});
$('#EndDate').daterangepicker({
singleDatePicker: true,
locale: { format: "MM/DD/YYYY" }
});
});
</script>
<div>
Start Date:
<%: Html.EditorFor(m => m.StartDate)%>
</div>
<br />
<div>
End Date:
<%: Html.EditorFor(m => m.EndDate)%>
</div>
</asp:Content>
ScreenShot