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. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to use custom helper for Tools controls ?

Platform: ASP.NET MVC |
Control: General


You can render For controls by using the custom HTML helper. Custom HTML helper is used to reduce the amount of tedious typing of HTML tags that you must perform to create a standard HTML page. You can render multiple control on a page by using the custom helper.


Render DatePicker control by using Custom HTML Helper

1)Using common custom Html Helpers for all the views by placing it in App_Code folder, we suggest you to add the controls by using the corresponding page view.

2)Define the variable in Model page as shown below,


Public Class DateSettings
    Public Property StartDate() As String
            Return mStartDate
        End Get
        Set(ByVal value As String)
            mStartDate = value
        End Set
    End Property
    Private mStartDate As String
End Class


3)You need to refer the following namespace in custom helper page,



@Import System.Web.Mvc.Html
@Import System.Web.Mvc


4)Now, Define the helper using the WebPageView element so that the corresponding page view’s scripts references will be inherited and you can add the required controls to the helper in custom helper page which is in App_Code folder.




@Helper  MyHelper(ByVal page As WebViewPage, ByVal model As NumericVB.DateSettings)
    @page.Html.EJ().DatePickerFor(Function(x) model.StartDate)
End Helper


5)Passing the model to the view page in the controller as shown below,



Function Index() As ActionResult
        Dim dateSettings As New DateSettings()
        dateSettings.StartDate = DateTime.Now.AddDays(-12)
        Return View(dateSettings)
 End Function



6)Add the helper created and pass the PageContext.Page to get the corresponding page element in view page.



@ModelType NumericVB.DateSettings
@CustomHelper.MyHelper(PageContext.Page, Model)




Similarly, we can render all our Controls by using custom helper.


2X faster development

The ultimate ASP.NET MVC UI toolkit to boost your development speed.
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.

Up arrow icon

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

Live Chat Icon For mobile