November Happy Hour will be moved to Thursday December 5th.

IPageRouteHelper.PageLink is null when using AjaxBeginForm() after upgrading CMS from 12.13.2 to 12.20.0

ZZ
ZZ
Vote:
 

HI,

I have just upgraded CMS ver. to 12.20.0 and now I am having this issue that IPageRouteHelper.PageLink is null when posting form via AjaxBeginForm().

This is the Ajax form and it posts to a POST method in TestPage name "LoginTest"

@using (Html.AjaxBeginForm("LoginTest", "TestPage", new { ReturnUrl = Model.GoToUrl }, new AjaxOptions
{
    UpdateTargetId = Model.xx,
    HttpMethod = "POST",
    InsertionMode = InsertionMode.Replace,
    OnSuccess = "xx",
    OnBegin = "xx",
    OnComplete = "xx"
}))

TestPage controller have this XXRedirection attribute

    [XXRedirection]
public class TestPageController : PageControllerBase<TestPage>
    {
 [HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<IActionResult> LoginTest(XX loginInput)
        {
            if (ModelState.IsValid)
                return await DoSomething();
            return PartialView(PartialLoginController, loginInput);
        }

}
-------------------------------------------------------------------------------------------
[AttributeUsage(AttributeTargets.Class)]
    public class XXRedirectionAttribute : ActionFilterAttribute
    {
        private Injected<IPageRouteHelper> _pageRouteHelper;
        private Injected<IContextModeResolver> _contextModeResolver;

        public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            base.OnActionExecuting(filterContext);
           
           var pageRouteHelper = _pageRouteHelper.Service;
          
           This is null
           var pageLink = pageRouteHelper.PageLink
          
           }



Here PageLink is null.  

Any input would be appreciated

#305052
Jul 12, 2023 12:09
Vote:
 

Is the instance of your content type TestPage also called TestPage? Try renaming it to something else then give it another go.

#305054
Jul 12, 2023 12:54
ZZ
Vote:
 

Thanks for the input.

TestPage is just an example name .

#305056
Edited, Jul 12, 2023 13:32
Vote:
 

Your TestPage is the name of your content type. But it looks as if TestPage is also the name of the instance of your page.

The reason why could be getting PageLink = null is because you've routed via an MVC route and not an Episerver route..i,e, one with your page context.

Just a theory, try renaming the instance of your page and see if it routes.

#305060
Jul 12, 2023 15:14
ZZ
Vote:
 

I think is due to the fact that I have routed via MVC and not via EpiServer route.

Ajax methods doesn't contains an extension method that takes URL as paramter. I don't know if there is another way to solve it except that I have to create my own extension method ?

#305107
Jul 13, 2023 9:35
ZZ
Vote:
 

I found out that this routing is not working due to CMS NuGet package upgrade. I have now downgraded packages to ->

    <PackageReference Include="EPiServer.CMS" Version="12.18.0" />
    <PackageReference Include="EPiServer.CMS.AspNetCore.HtmlHelpers" Version="12.12.1" />

and now AjaxBeginForm() works as expected. 

I think I would keep CMS at 12.18.x ver. for now,

#305154
Jul 14, 2023 7:14
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.