You can do three ways:
1) For simple controls without much logic, you can create a new instance of a custom view model for the control: Html.RenderPartial ("YourControl", new YourControlViewModel () {Param1 = "value1", Param2 = Model.AnotherValue});
2) If you need rear-end logic for control, you can use Html.RenderAction ("ActionName", "SomeControllerName", RouteValuesDictionary); It will call the standard action of the controller, use the view and paste the result back into the page. You can add the [ChildActionOnly] attribute to the controller method to ensure that the method will be available only from Html.RenderPartial. It violates the MVC principle somewhat (view should not call the controller), but it is great for widgets and is used in the Ruby on Rails world without any problems. You can check out the excellent article from Haacked
3) Create your own html helper for tasks like date formatting, calculation, etc.
In your case, I would choose number two.
jhexp
source share