Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Saied 349 posts 674 karma points
    Sep 02, 2015 @ 02:53
    Saied
    0

    Why does Umbraco return the current view if I am returning a different view?

    I created a Products.cshtml document type and template in the backoffice. On the Products.cshtml, I have a partial view that I created in Visual Studio called ProductsFilter.cshtml. I have a controller called ProductsFilterController that has one method on it:

    public class ProductFilterController : SurfaceController
    {
        [HttpPost]
        public ActionResult SearchResults(ProductFilterModel productFilterModel)
        {
    
            return View(productFilterModel);
        }
    }
    

    My SearchResults.cshtml which was also created in Visual Studio holds is the View that I pass the ProductFilterModel to, but when I look at the Url in the browser, it points to http://localhost/products with the SearchResults view. I was expecting it to be http://localhost/productsfilter/searchresults

    Can someone explain why this is happening?

  • Alex Skrypnyk 6147 posts 24056 karma points MVP 8x admin c-trib
    Sep 02, 2015 @ 08:53
    Alex Skrypnyk
    0

    Hi Saied,

    Umbraco create routes by your pages, so if you create Products page you have page http://domain.com/products.

    Partial views can't change page url.

    Thanks, Alex

  • Saied 349 posts 674 karma points
    Sep 02, 2015 @ 13:52
    Saied
    0

    Hi Alex,

    Just so I understand correctly, even though I have return View(productFitlerModel), it will render the view on the /products.cshtml page?

    If I am not using a partial, would it make a difference?

    Also, if it is a view in the umbraco backoffice, would it redirect to that view and is there an umbraco way to do that?

  • Alex Skrypnyk 6147 posts 24056 karma points MVP 8x admin c-trib
    Sep 03, 2015 @ 10:38
    Alex Skrypnyk
    0

    Saied, if you are on the Umbraco page, Umbraco does routes solving. So Umbraco decided what template to show at /prdoucts page. You can inject into that process

    https://our.umbraco.org/documentation/reference/routing/custom-controllers

    http://umbraco.com/follow-us/blog-archive/2014/1/27/a-practical-example-of-route-hijacking-in-umbraco

Please Sign in or register to post replies

Write your reply to:

Draft