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
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
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 theProducts.cshtml
, I have a partial view that I created in Visual Studio calledProductsFilter.cshtml
. I have a controller calledProductsFilterController
that has one method on it:My
SearchResults.cshtml
which was also created in Visual Studio holds is the View that I pass theProductFilterModel
to, but when I look at the Url in the browser, it points tohttp://localhost/products
with theSearchResults view
. I was expecting it to behttp://localhost/productsfilter/searchresults
Can someone explain why this is happening?
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
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?
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
is working on a reply...