How to?
4 Apr 2018 / 1 minute to read
Render DateRangePicker from Code behind
DateRangePicker can be rendered from the code behind by initializing the required properties in controller and passing those properties via ViewData or Model to the client side.
The following code illustrates the initialization of DateRangePicker properties in the controller.
//Namespace to get the JavaScript (DateRangePicker) component properties
using Syncfusion.JavaScript.Models;
namespace MvcApplication.Controllers
{
public class DateRangePickerController : Controller
{
// GET: DateRangePicker
public ActionResult DateRangePickerFeatures()
{
//Initializing the DateRangePicker model
DateRangePickerProperties DateObj = new DateRangePickerProperties();
//Initializing the datasource and other properties
DateObj.Width = "300px";
DateObj.StartDate = "2/2/2018";
DateObj.EndDate = "2/25/2018";
//Passing DateRangePicker properties using the ViewData
ViewData["DateModel"] = DateObj;
return View();
}
}
}
Binding the DateRangePicker properties passed via ViewData from the controller in the client side as below.
@{
Html.EJ().DateRangePicker("searchCustomer",(Syncfusion.JavaScript.Models.DateRangePickerProperties)ViewData["DateModel"]).Render();
}
Was this page helpful?
Yes
No
Thank you for your feedback!
Thank you for your feedback and comments. We will rectify this as soon as possible!
An unknown error has occurred. Please try again.
Help us improve this page