Search code examples
sitefinity

sitefinity widget using query string


I like to build a widget that will take in the query string as parameters. Is there a build in method for this in sitefinity? Or is this something I have to do in code? I like to leverage sitefinity toolset .

domain.com/shoes?type=sneakers&sort=price_ascending

namespace SitefinityWebApp.Mvc.Controllers
{
    [ControllerToolboxItem(Name = "Shoes", Title = "Shoes", SectionName = "MVC")]
    public class ShoesController : Controller
    {
        public string type{ get; set; }
        public string sort{ get; set; }

Solution

  • Should take in routed parameters like a regular MVC controller. So like

    public ActionResult Index(string type, string sort){
     this.sort = sort;
     this.type = type;
     ....
    }
    

    There's nothing to automatically hydrate those public properties (and thank god, can you imagine the havok if someone could change them arbitrarily?)

    But you can use Telerik.Sitefinity.Services.SystemManager.CurrentHttpContext to get the HTTP context that has the regular Request.Querystring to use.

    Think of Sitefinity more as like a regular ASP.NET MVC site, with API helpers instead of a magic "do it the sitefinity way" kinda thing you know :) The ability to have multiple controllers on a page is GREAT.