Copied to clipboard

Flag this post as spam?

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


  • Phill 115 posts 289 karma points
    Feb 29, 2016 @ 03:59
    Phill
    0

    How to return to page when using IContentFinder and/or Partial View?

    Hi there,

    I'm using an IContentFinder on a specific DocType so that I can have urls that looks like this: anypage/ProductDocType/123 (where 123 is unique ID of record in custom table, not a umbraco node).

    Currently on my Product Page I have a partial view that displays Product Details with a small for that allows me to modify some properties. I post this information to my custom SurfaceController using an Umbraco Form and all that works as expected.

    The challenge is when I want to return back to that same page and display the same product 123. If I use "return PartialView("template", productModel) I get raw html displayed, but no Umbraco page so the master layout is missing. If I use return CurrentUmbracoPage() or RedirectToCurrentUmbracoPage() I get returned to the right page and it's all formatted but my data isn't there because it has removed /123 from the URL and I'm not able to reload the product from the database.

    Anyone have any ideas how I can return to the page and still maintain the Umbraco Page Context and keep my URL untouched?

    Thanks in advance. Phill

  • Phill 115 posts 289 karma points
    Mar 01, 2016 @ 01:10
    Phill
    0

    A little more information on my issue. I render Partial View using the following: @Html.Action("ViewDetailAction", "ProductDetailController") When page is loaded, the ViewDetailAction gets the last segment of the URL, checks to see if it's a valid ProductID and if it is, goes to the DB to get the product data, populates the ProductViewModel and all is good.

    Then when I try to update this product and redirect to same page, the UpdateDeatails action is called and that works fine, until it tries to go back to the page. The closest to success I've had is using return PartialView but all formatting /page context is gone. So the next closest is return CurrentUmbracoPage() which then causes ViewDetailAction to be called again. This looks promising but the issue is that when I try to get the last segment of the URL for the product ID, Request.Url is no longer the actual URL but rather it becomes /umbraco/RenderMvc

    So how can i get the actual URL that is visible and displayed in the browser address bar? Am I doing this whole thing the wrong way?

    p.s. If anyone knows of anywhere else to post Umbraco questions that have a higher chance of getting responded to, would love to know. Is StackOverflow a better place to post?

    Thanks again! Phill

  • Phill 115 posts 289 karma points
    Apr 05, 2016 @ 17:51
    Phill
    0

    Just bumping this one as I have to get back to resolving this issue now on the project I'm working on. Any help/ideas would be greatly appreciated.

    Phill

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Apr 05, 2016 @ 19:29
    Nicholas Westby
    0

    Sounds like you may have found a mostly working solution, but you just need the proper URL. Maybe you could add it to the HTTP context items. For example, from a CSHTML file, you should be able to do this:

    Context.Items.Add("Actual URL", Request.Url.ToString());
    

    From a controller, you might have to qualify that differently (e.g., System.Web.HttpContext.Current.Items).

    Not sure if CurrentUmbracoPage() will initiate a new request or not (which would mean you can't access the Context.Items), but it's worth a try.

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Apr 05, 2016 @ 19:34
    Nicholas Westby
    0

    Another idea would be to redirect from your controller to a URL with a query string:

    return Redirect("/some-url?some=thing");
    

    The idea would be that the query string would contain any information (perhaps some identifier) that would allow you to display the same page differently.

  • Phill 115 posts 289 karma points
    Apr 05, 2016 @ 22:18
    Phill
    0

    Hi Nicholas,

    Thanks for your input, greatly appreciated.

    I do have a really clunky solution working but I don't like it at all. In my ActionResult I have the following:

    
                var currentUrl = new Uri(Request.Url, Request.RawUrl);
                Response.Redirect(currentUrl.ToString(), true);
                return CurrentUmbracoPage();
    

    There are a number of issues here (on top of the fact that it's what I would call a "hack"). First issue is that if you try to get Request.Url it's value is actually umbraco/RenderMvc which of course is totally useless. The above gives me my actual URL with the ID that I've added to the URL and use with my Custom Content Finder. However when you step through this code it throws an error that HTTP Headers can't be modified... (or something like that). It does still redirect to itself but I really dislike that it throws an error (the cshtml view also throws an error). Secondly, because it's an ActionResult I still have to include the "return" which of course never gets hit.

    So it works but in a very hacky way and I'm just hoping that someone has come across this and has a better/proper way to be doing this.

    I will try your suggestion to add it t context items but I fear that the value for request.url will be umbraco/rendermvc and not my actual url.

    Phill.

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Apr 05, 2016 @ 23:13
    Nicholas Westby
    100

    Rather than this:

    var currentUrl = new Uri(Request.Url, Request.RawUrl);
    Response.Redirect(currentUrl.ToString(), true);
    return CurrentUmbracoPage();
    

    Why not do this?:

    var currentUrl = new Uri(Request.Url, Request.RawUrl);
    return Redirect(currentUrl.ToString());
    

    Not sure what doing a redirect followed by returning the current Umbraco page would do (other than just redirect and ignore the return of the current Umbraco page).

  • Phill 115 posts 289 karma points
    Apr 06, 2016 @ 17:19
    Phill
    0

    Not sure why I never thought to try "return redirect(..." I will give that a try to see if it still throws an error or not (but user doesn't see because they redirect means error can't be displayed).

    Will let you know what result is. All seems rather clunky but if I can at least get errors to go away I'll be happy.

    Thanks again. Phill

Please Sign in or register to post replies

Write your reply to:

Draft