We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to define properties for FOR controls?

Platform: ASP.NET MVC |
Control: DatePicker |
Published Date: April 22, 2015 |
Last Revised Date: May 9, 2019

Description

While creating “FOR” controls, you have to define the properties in the View model when unobtrusive is in the enabled mode.

Solution

While creating “FOR” controls in the MVC application, when the unobtrusive is disabled, you can define the properties of your components in the builder itself, as shown in the following code example.

CSHTML

  @Html.EJ().DatePickerFor(model => model.datepicker1).Value("2/12/2013").Locale("en-GB")

When the unobtrusive is in the enabled state, you have to define the properties of your components in the model. You have to define the DatePicker model in the builder as shown in the following code example.

CSHTML

@Html.EJ().DatePickerFor(model => model.datepicker1, (Syncfusion.JavaScript.Models.DatePickerProperties)ViewData["date"])

Using that object you can set the value of the properties as shown in the following code example.

Controller

  public ActionResult Index()
  {
        Incident inc =new Incident();
        inc.datepicker1 =System.DateTime.Now;
        DatePickerProperties datemodel = new DatePickerProperties();
        datemodel.Locale = "en-GB";
        datemodel.ShowOtherMonths = false;
        ViewData["date"] = datemodel;                        
        return View(inc);
  }          

Similarly, you can access all the properties and events of your components from the controller when the unobtrusive is enabled state.

You can download the complete sample under the following location.

Sample

 

2X faster development

The ultimate ASP.NET MVC UI toolkit to boost your development speed.
ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon