I built a custom module that manages appointments for a service-based company. All of the current functionality is contained in the admin section. I have not used a single ContentItem or ContentPart. All the models are just plain records.
I’m looking to create a widget to expose the ability to sign up for an appointment from the front end. I have a partial view and a controller that handles the display and form submit, but I’m not sure how to tie that into a widget that can be placed in one of the content zones of the front-end.
I’ve spent quite a bit of time researching this, and can’t find a good path to follow. (I’ve tried a few and got sub-optimal results)
Any suggestions?
The best answer for me was to create a widget Type definition in the migration.cs file of the module:
Then create a handler for that widget at
/MyModule/Handlers/CreateAppointmentWidgetHandler.cs:Then create a matching widget template at
/MyModule/Views/Widget-CreateAppointmentWidget.cshtmlthat inserts the Partial View:The above code grabs the partial view
/MyModule/Views/CreateAppointment.cshtml.Thanks to Giscard’s suggestion, I was able to correct the links rendered from CreateAppointment.cshtml by using @Url.RouteUrl() and defining named routes to point where I needed the action and ajax requests to go.
The nice thing about this solution is that it provided a way to create the widget without having to rework my models to use Orchards ContentPart functionality.