Developer forum

Forum » Templates » Global:Area.ID with razor?.

Global:Area.ID with razor?.

Mikkel Toustrup Olsen
Reply

Hello,

I came across a rather odd issue. Isn't it possible to retrieve the Global:Area.ID with razor within a paragraphtemplate?.

My code returns "" - which means the ID doesn't exist? ..

@{

    var areaId = GetValue("Global:Area.ID"); (have tried GetValue, GetString, Integer and etc. without any luck..)
    switch(areaId)
    {
        case "1": pathForDepartmentList = "Default.aspx?ID=119";
        break;
        case "2": pathForDepartmentList = "Default.aspx?ID=119";
        break;
        case "4": pathForDepartmentList    = "Default.aspx?ID=119";
        break;
        default: pathForDepartmentList    = "rammer ikke!!";    
        break;
        
    }
}

 

<form method="post" action="@pathForDepartmentList">

some code here...

</form>

 

Regards,

MikkelTO


Replies

 
Mikkel Ricky
Reply
This post has been marked as an answer

@Pageview.Area is a reference to the current Area, i.e. you can just write @Pageview.Area.ID to get the current Area (website) id.

Rather that using a switch statement in your template, you should consider using an item with a property called DepartmentListId as website property and then write something like

<form action='/Default.aspx?ID=@Pageview.Area.Item["DepartmentListId"]'> … </form>

 

in your template

Best regards,
Mikkel

Votes for this answer: 1

 

You must be logged in to post in the forum