Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RedirectToUmbracoPageResult - Extended to allow a Guid #8139

Merged

Conversation

poornimanayar
Copy link
Contributor

@poornimanayar poornimanayar commented May 19, 2020

Currently the RedirectToUmbracoPageResult only allows a pageId or an IPublishedContent. I think it will be good if we can extend it to handle a Guid key.

To test this use the following code. I have used it on my local install which has the starter kit

TestSurfaceController.cs

public class TestSurfaceController : SurfaceController
    {
        public ActionResult Index()
        {
            return this.PartialView("TestIndex");
        }

        [HttpPost]
        public ActionResult PostToProductsPage()
        {
            var firstChild = CurrentPage.FirstChild();
            return this.RedirectToUmbracoPage(firstChild.Key);
        }

        [HttpPost]
        public ActionResult PostToProductsPageWithQueryString()
        {
            var firstChild = CurrentPage.FirstChild();
            return this.RedirectToUmbracoPage(firstChild.Key, "param=1");
        }

        [HttpPost]
        public ActionResult PostToProductsPageWithQueryStringCollection()
        {
            var firstChild = CurrentPage.FirstChild();
            var paramCollection = new NameValueCollection();
            paramCollection.Add("param1", "1");
            paramCollection.Add("param2", "2");
            return this.RedirectToUmbracoPage(firstChild.Key, paramCollection);
        }
    }

TestIndex.cshtml

@inherits UmbracoViewPage

@using (Html.BeginUmbracoForm<TestSurfaceController>("PostToProductsPage"))
{
    <input type="submit" value="Redirect to page" />
}

@using (Html.BeginUmbracoForm<TestSurfaceController>("PostToProductsPageWithQueryString"))
{
    <input type="submit" value="Redirect to page with querystring param" />
}

@using (Html.BeginUmbracoForm<TestSurfaceController>("PostToProductsPageWithQueryStringCollection"))
{
    <input type="submit" value="Redirect to page with multiple querystring params" />
}


And add this line to the Home.cshtml

@Html.Action("Index","TestSurface")

@nul800sebastiaan nul800sebastiaan merged commit c1e2f8f into umbraco:v8/contrib Aug 31, 2020
@nul800sebastiaan
Copy link
Member

Thanks @poornimanayar - looks good! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants