Copied to clipboard

Flag this post as spam?

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


  • Matt 308 posts 730 karma points
    Mar 05, 2020 @ 08:54
    Matt
    0

    Create a redirect page

    Hi all,

    I'm looking at creating a redirect page, so if you click on the page it redirects you to an external URL.

    I've created a doc type with a template called "Page Redirect" with a field called Link Target inside my template I have the following code;

    @inherits Umbraco.Web.Mvc.UmbracoViewPage<ContentModels.PageRedirect>
    @using ContentModels = Umbraco.Web.PublishedModels;
    
    @{
        Layout = "master.cshtml";
        string linkUrl = "";
        if(Model.HasValue("linkTarget"))
        {
           var linkItem = Model.linkTarget.First;
           linkUrl = linkItem.link;
        }
    
        if(!String.IsNullOrEmpty(linkUrl))
        {
           Response.Redirect(linkUrl);
        }
    }
    

    But I'm getting the following error;

    CS1061: 'PageRedirect' does not contain a definition for 'linkTarget' and no accessible extension method 'linkTarget' accepting a first argument of type 'PageRedirect' could be found (are you missing a using directive or an assembly reference?)

    Any advice to get this working? :)

  • Shaishav Karnani from digitallymedia.com 349 posts 1631 karma points
    Mar 05, 2020 @ 13:32
    Shaishav Karnani from digitallymedia.com
    0

    Hi Matt,

    I think you need to change var linkItem = Model.linkTarget.First;

    To

       var linkItem = Model.LinkTarget.First;
    

    Make link capital and try.

  • Matt 308 posts 730 karma points
    Mar 05, 2020 @ 14:05
    Matt
    0

    Hi Shaishav,

    Thanks for reply;

    This is what I get now;

    CS0815: Cannot assign method group to an implicitly-typed variable

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies