Copied to clipboard

Flag this post as spam?

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


  • P.J. Melies 18 posts 108 karma points
    Apr 14, 2021 @ 17:41
    P.J. Melies
    0

    Render controller for Macro

    We have a macro partial view that requires us to run some logic in a controller in the GET action based on query string parameters before rendering the partial view.

    We have a corresponding surface controller to handle POST actions but I can't figure out how to hook into the GET action in order to run the required logic on the initial request.

    I've tried coding Index() and Render() methods in the surface controller but those are never executed.

    Is it even possible for me to do what I'm attempting? If not I could just create a specific document type, template and partial view but we were hoping to keep this logic in a macro to make it easier on the designer.

  • Huw Reddick 1737 posts 6098 karma points MVP c-trib
    May 02, 2021 @ 23:17
    Huw Reddick
    0

    I don't think you can achieve what you want, however there may be a way around it, what exactly do you need to do?

    If you want to pass values to the macro based on the querystring, you could maybe do something like

    In your MacroPartial

    @Html.Action("Index", "MacroTestSurface", new { request = Request.QueryString })
    @if (TempData.ContainsKey("page"))
    {
        <p>Page = @TempData["page"]</p>
    }
    

    Controller

    public class MacroTestSurfaceController : SurfaceController
    {
        public ActionResult Index()
        {
            if (Request.QueryString.AllKeys.Contains("page"))
            {
                TempData["page"] = Request.QueryString["page"];
            }
            return Content("");
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft