PopUp

Framework Core
Tag Helper <pop-up />

Holds all previous page field values in a hidden field when posted to from a previous page with the intention of returning back to the parent with all the "unsaved" values still on the page.

Tag Helper <pop-up-edit />

Show an edit button on the page which collects all fields and navigates to an Edit action ready for returning.

string Action

The action to navigate to when editing.

Tag Helper <pop-up-from />

Sets the page to return to after a pop up return. This is placed on the parent page to be used by the <pop-up /> tag on the child page.

string CurrentView

The action to navigate back to after editing.

Tag Helper <pop-up-return />

Used exclusively for a Pop Up return page called Views / Shared / PopUpReturn.cshtml when returning to a different controller after a Pop Up.

PopUpHelper

Helper functions for Pop Up.

Constructors

public static class PopUpHelper
HasPopUp

public static bool HasPopUp(HttpContext httpContext)

Does the posted data contain a PopUp?

PopUpFrom

public static string PopUpFrom(HttpContext httpContext)

Returns the name of the PopUp control that is the parent of this form.

Parse<>

public static T Parse<T>(HttpContext httpContext) where T : new()

Parses a PopUp into the provided type.

SetSamePage

public static void SetSamePage(dynamic viewBag)

Flag that the SamePage property should be set to true and so do not reencode the values a second time.

PopUpFrom

public static void SetReturnFromPopUpChild(dynamic viewBag)

Flag that the ReturnFromPopUpChild property should be set to true and so do set a popup field on the page with remaining values for other pages.

Notes

To use this control put the <pop-up /> control on the child page.It will encode all the fields and make them available for a return.

To return you can optionally in C# check PopUpHelper.HasPopUp() to see if this has a return. If so then you can switch (PopUpHelper.PopUpFrom()) to get the calling page as defined in the PopUpFrom helper.

To return to same controller use Parse<> to obtain the model.

To return to a different controller call a PopUpReturn page which has

PopUp and return on same Controller.

Razor
<pop-up />
C#
public ActionResult MyItemSet
{
if (Model.IsValid)
{
...
}
else
{
var p = PopUpHelper.Parse<ModelGet_Result>();
PopUpHelper.SetSamePage();
return View("MyView", p);
}
}

PopUp and return to different Controller(s).

Razor - Parent Page
<pop-up-from current-view="/Area/MyController/Action" />
Razor- Child Page
<pop-up />
C#
public ActionResult EditReturn()
{
if (PopUpHelper.HasPopUp())
{
switch (PopUpHelper.PopUpFrom())
{
case "/Area/MyController/Action":
ViewBag.Action = "EditPopUpReturn";
ViewBag.Controller = "MyController";
ViewBag.Route = "MyArea"; // use "" if no area.
break;

default:
return RedirectToAction("Index")
}
return View("PopUpReturn")
}
else
return RedirectToAction("Index");
}
C# to put in Views / Shared / PopUpReturn.cshtml
@using ShareIt.Library

@using (Html.BeginForm(PopUpHelper.GetReturnAction(ViewBag), PopUpHelper.GetReturnController(ViewBag), new { area = PopUpHelper.GetReturnRoute(ViewBag) }))
{
@Html.AntiForgeryToken()
<pop-up-return />
}

PopUp from Child through to sub Child.

Razor - Parent Page
<pop-up-from current-view="/Area/MyController/Action" />
Razor- Child Page
<pop-up />
<pop-up-from current-view="/Area/MyChildController/Action" />
Razor- Sub Child Page
<pop-up />
C# on Sub Child
public ActionResult EditReturn()
{
if (PopUpHelper.HasPopUp())
{
switch (PopUpHelper.PopUpFrom())
{
case "/Area/MyController/Action":
PopUpHelper.SetReturn("EditPopUpReturn", "MyController", "MyArea");
PopUpHelper.SetReturnFromPopUpChild();
break;

default:
return RedirectToAction("Index")
}
return View("PopUpReturn")
}
else
return RedirectToAction("Index");
}
C# to put in Views / Shared / PopUpReturn.cshtml
@using ShareIt.Library

@using (Html.BeginForm(PopUpHelper.GetReturnAction(ViewBag), PopUpHelper.GetReturnController(ViewBag), new { area = PopUpHelper.GetReturnRoute(ViewBag) }))
{
@Html.AntiForgeryToken()
<pop-up-return />
}