Sitefinity Development with MVC: Returning a Partial View

by Stephen Horn Mar 26, 2015

For years Sitefinity has been a great CMS. Since Sitefinity has been around for quite a while now, and it was built using the .NET Framework, it's only natural that they leveraged the power of the Web Forms programming module. It's what was available, and in many respects, was very good.  Then came along the MVC module. And many swooned. Eventually Sitefinity started to support MVC, and did a pretty decent job of it.  As a developer it's not too hard to work with MVC within Sitefinity, however one thing has always been a bit of a pain; returning a Partial View.

You can see form this forum post, that there were some rocky starts to trying to get the data back from the server to update a page using traditional MVC methods. In this case, using JSON  (JavaScript Object Notation).

JSON Action Result Returns Whole Page

Well, they solved the JSON issue, but what if you do not want to use a JsonNetResult? Maybe you want to return a regular Partial View. Well, that is supported as well!  Here's how. 

A traditional method signature to retrieve a partial view looks like this:

[HttpGet]
public PartialViewResult GetMyResult()

However, doing this in Sitefinity will return the entire page again!PartialFilter4

Well, Sitefinity is aware, and they have created a nice action filter attribute for us to use. Simply decorate your method with a "StandaloneResponseFilter" tag.

[HttpGet]
[StandaloneResponseFilter]
public PartialViewResult GetMyResult()

Now when you make that call, you will get just the partial view you want. 

PartialFilter3

From the Browser View:

PartialFilter2

Want to see this "live" for yourself? On our example page you will find two buttons (toggles). Go ahead and push the first one and see the desired results. Then click the 2nd button, and see the difference live!

Sitefinity Partial View Filter Example

Checking out what the browser is seeing in the response, it's easy to see what is going on! 

So that's all there is to it. We've helped many a client solve issues just like this one, and if your team is stuck on a Sitefinity development issue, we would love to help you as well!

  New Call-to-action