OK,
So I am doing something that doesn’t feel right, but I am not sure what my options are or what are the better ways. This is an high level overview at first so you can see what I am trying to achieve:
In my backoffice, I have the following structure:
- Home
- Products
- Product
- Products
When the user goes to the /products
page, they form to search for products first, so what I did was put this search form in a partial view called ProductFilter.cshtml
in my views\partials\
folder. When the user clicks submit, I have another view SearchResults.cshtml
that is located in views\ProductFilter\
.
In my ProductFilterController
, I have the following code which passes the model to the SearchResults
view, however, since SearchResults
is not a template in Umbraco, the /products
page gets posted with the search results, which works, but I am not sure if this is a good thing to do. Also, when the user clicks the browser refresh, it posts again.
[HttpPost]
public ActionResult SearchResults(ProductFilterModel productFilterModel)
{
var db = new Database("productsDb");
var productSearchResultsModel = new ProductSearchResultsModel
{
ProductFilterModel = productFilterModel,
Products = db.Fetch<ProductViewModel>(@"SELECT *
FROM Products")
};
return View(productSearchResultsModel);
}
Thanks,
Saied
This is a companion discussion topic for the original entry at https://our.umbraco.com/forum/71189-having-a-view-post-back-to-itself-with-a-different-view-am-i-doing-it-correctly