The following tutorial demonstrates how to create a simple MVC Books widget. You leverage the attribute routing of MVC 5 in the context of a Sitefinity CMS widget. The Books widget displays a list of books on the frontend and tracks on the client the points retrieved for each book.
Sitefinity CMS makes it possible to have MVC widgets that are stored in separate assemblies. The following sample creates the Books widget in a separate assembly.
Perform the following:
In the MVC/Models folder, create a new class named Book. The class needs to have:
The Book class should look similar to the following:
Next, in the MVC/Models folder, you create a new class named BooksViewModel. The class needs to have the following properties:
The BooksViewModel class should look similar to the following:
Use the following code sample:
You need to create an Index view, because this is the only view that is used by the BooksController. To do this, you must create a new Razor view named Index and to place it in the MVC/Views/Books folder.
To create the Index view, use the following code:
NOTE: You can create a Razor view in a class library project by selecting HTML Page from the Add New Item dialog, and then renaming the file extension to .cshtml. In the file properties, set the view as Embedded Resource.
NOTE: Be sure to mark the script as an Embedded Resource in the file properties.
You can now build the project and test the result by placing the Books widget on a page.
Back To Top
Copyright © 2018 Progress Software Corporation and/or its subsidiaries or affiliates.
All Rights Reserved.