How to access PageData in a WebMatrix C# file? -


many of webmatrix examples , tutorials use pagedata transfer data between pages during page construction process (e.g. between content page , layout page). example...

@{     layout = "/shared/_layout.cshtml";      pagedata["title"] = "passing data";     pagedata["tracedata"] += "start of main page.|"; } 

this works fine simple situations, have enough repeated code using pagedata want refactor c# classes. in none of examples or documentation have been able find, there "using" statements, or other context indicate object pagedata (or property of). in cshtml file it's "just there" magic have not yet been able determine.

how can access pagedata in c# class? example, able this...

public static class mytrace {     public static void add(string amessage) {         pagedata["tracedata"] += amessage + "|";     }      public static string read() {         return pagedata["tracedata"];     } } 

(please note: tracing example not represent full extent of usage, simple example demonstrate point. if there better ways implement tracing system in webmatrix, while find out that, not point of question.)

to access pagedata property, try following code:

webpagecontext.current.pagadata 

the webpagecontext type available in system.web.webpages namespace.


Comments

Popular posts from this blog

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -