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 04, 2015 @ 16:06
    Saied
    0

    Having a view post back to itself with a different view. Am I doing it correctly?

    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

    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 forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" button below.

    Continue discussion

Please Sign in or register to post replies