Copied to clipboard

Flag this post as spam?

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


  • Jay 49 posts 211 karma points
    Jan 02, 2015 @ 15:23
    Jay
    0

    How To Return View For Parent Page (With ModelStateError) From Partial View Submit?

    Dear Umbracians,

    I have multiple pages of document type LandingPage. These landing pages include a MemberAddressForm, which is a partial view for requesting some information from people signing up.

    This partial view submits to my MemberAddressFormController, the controller for my MemberAddressForm partial view.

    In MemberAddressForm.Submit, I am unable to return CurrentUmbracoPage. I get a routing exception, because this method call comes from a partial view, rather than the partial view's parent page.

    I want to set a ModelState error message. I have to return a view in order to be able to use this ModelState error message in my view.

    I am asking myself how to return the current (parent) page as a view. I can not simply do...

    return View("/Views/LandingPage.cshtml")
    

    ... because this is a template.

    Returning the current template as a View can't work because it is unknown which content page the template needs to be applied to.

    I understandably get the following error:

    Cannot return the IPublishedContent because the UmbracoHelper was constructed with an UmbracoContext and the current request is not a front-end request.
    

    Here is the code in my MemberAddressFormController:

    private ActionResult Submit(User newUser, int pageID)
    {
        if (!ModelState.IsValid)
        {
            ModelState.AddModelError("ModelStateInvalid", "Model state isn't valid.");
            return Redirect(this.Request.UrlReferrer.ToString()); // how to redirect to parent page as view with useable modelstate error?
        }
    }
    

    I need to know how to:

    1. Set a ModelState error in a submit action initiated by a partial view.
    2. Return a view to the parent page of the partial view that initiated this submit action.
    3. Maintain the url query string that the user used when visiting the parent page in the first place.

    What is the best practice for this?

  • Jay 49 posts 211 karma points
    Jan 05, 2015 @ 09:23
    Jay
    0

    Anybody know how to do this?

  • Jay 49 posts 211 karma points
    Jan 06, 2015 @ 10:16
    Jay
    0

    How do I return an UmbracoPage View from a post method Submit, initiated by a MemberAddressForm partial view?

    I'm currently using redirects. I want to use views.

  • Jay 49 posts 211 karma points
    Jan 14, 2015 @ 12:35
    Jay
    0

    Is this even possible ?

Please Sign in or register to post replies

Write your reply to:

Draft