The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
As we are seeing more and more developers who use their MVC widgets in Sitefinity, we spent some time to make their life easier for the 6.2 release. A lot of issues reported in the past have been fixed, and we have also introduced support for some new functionality requested by developers. This blog post provides the highlights.
In 80% of the controllers, the name of an action is the same as the name of the method representing this action. However, there are cases where these may be different. For whatever reason, developers may want their method to respond to an action, whose name is different. Phil Haack, who worked on the ASP.NET MVC framework at Microsoft, described what makes a normal method to be an action in a blog post a while ago: How a method becomes an action
In a common MVC scenario, the requested URL contains information about the controller and action. The routing mechanism executes your controller and calls the method for the action in the URL. What happens if the controller does not implement such an action? In normal ASP.NET MVC, you would get a 404 Not Found response. In Sitefinity, nothing happens (an empty response).
The reason that Sitefinity behaves differently is that it can handle multiple controllers on a single page. If one of the controllers on that page cannot handle the action, the others should be given a chance. The page cannot return a 404 only because a small portion of it cannot handle the request.
This behavior leads to some weird situations when there are multiple controllers on the same page. Switching into detail mode for one of them (adding an item to the URL), makes the other control disappear (because it thinks of the new URL as an action it doesn’t support). Previously, developers had no control over these scenarios.
Sitefinity 6.2 introduces a hook which lets them implement “default” behavior in their controllers. You can override the HandleUnknownAction method in your controller.
One of the features commonly used with MVC is the handling of custom input forms. And one of the features commonly used with input forms is validation. In the WebForms model, developers had a limitation of only using one <form> tag per page. Because Sitefinity combines the WebForms model with the MVC model in its Hybrid mode, this limitation was still there, and it created problems for validation. Sitefinity used custom script for submitting the form, but this custom execution did not fire validation logic. This has been reworked in 6.2.
Now you can use client validation in Hybrid mode without worries. Sitefinity fully supports the unobtrusive client validation approach based on the jQuery validation plugin. You can decorate your model classes with some attributes and based on those, attributes are also added to the generated HTML for the form fields. The jQuery validation plugin uses those HTML attributes to check the specific requirements for each field, and prevents submission of the form if the values are not valid. For more information on using unobtrusive client validation with MVC, please refer to the following article: Unobtrusive client validation
The features described above were requested by the Sitefinity developer community in the months before the 6.2 release. We continue to listen to your suggestions. If you have requests for anything else in our MVC support, please get in touch.
View all posts from Slavo Ingilizov on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Subscribe to get all the news, info and tutorials you need to build better business apps and sites
You have the right to request deletion of your Personal Information at any time.
You can also ask us not to pass your Personal Information to third parties here: Do Not Sell My Info
Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.
Copyright © 2021 Progress Software Corporation and/or its subsidiaries or affiliates.All Rights Reserved.
Progress, Telerik, Ipswitch, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks for appropriate markings.