1

Getting these error in my Razor viewpage:

HtmlString GetActionUrl()
{
    return Url.Kentico().AuthenticateUrl(Url.Action("Upload", "ImageUploader", new
    {
        pageId = Context.Kentico().PageBuilder().PageIdentifier
    }), false);
}

enter image description here

Added WebConfig:

<system.web.webPages.razor>

<host factoryType="System.Web.Mvc.MvcWebRazorHostFactory, System.Web.Mvc, Version=5.2.7.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
<pages pageBaseType="System.Web.Mvc.WebViewPage">
  <namespaces>   
    <add namespace="System.Web.Mvc"/>
    <add namespace="System.Web.Mvc.Ajax"/>
    <add namespace="System.Web.Mvc.Html"/>
    <add namespace="System.Web.Optimization"/>
    <add namespace="System.Web.Routing"/>
    <add namespace="ResolutionDigital"/>
    <add namespace="Kentico.Content.Web.Mvc"/>       
    <add namespace="Kentico.PageBuilder.Web.Mvc"/>      
    <add namespace="Kentico.Web.Mvc"/>
  </namespaces>
</pages>

</system.web.webPages.razor>

Am i missing some directives or references? Can anyone help? What am i missing?

sapana
  • 46
  • 6
  • 1
    What version of Kentico Xperience are you using? Do your other Views compile without errors? Have you tried a minimal reproduction? Have you tried this code in the Dancing Goat sample application? – seangwright Aug 11 '21 at 23:01
  • Hello @seangwright i have updated my answer down below! I hope this helps. – sapana Aug 12 '21 at 10:19
  • Hi, i think i have solved the issue here, kentico 13 allows the simlar workflow in class and controller not in razor view. I hope this helps – sapana Feb 28 '22 at 08:54

1 Answers1

1

Just adding my comment here that I solved the issue somehow. I am using xperience 13 for the project. Probably i was having the version issues while adding the same code as kentico 12. But we can use this instead.

var urlHelper = new UrlHelper(HttpContext.Current.Request.RequestContext);

string GetActionUrl()
{
    return urlHelper.Kentico().AuthenticateUrlRaw(urlHelper.Action("Upload", "ImageUploader", new
    {
        pageId = Service.Resolve<IPageDataContextRetriever>().Retrieve<TreeNode>().Page.DocumentID
    }), false);
} 

I am sure you need to add some reference as well.

@using CMS.Core @using CMS.DocumentEngine

Thankyou!

sapana
  • 46
  • 6