Developer forum

Forum » CMS - Standard features » how can i set a razor varialbe that i can access and manipulate across templates

how can i set a razor varialbe that i can access and manipulate across templates

Hans Ravnsfjall
Hans Ravnsfjall
Reply

A general razor question

In my master pagetemplate, I want to declare at variable var totalcount=0:

And in my paragraph templates, I want to add to this variable like this @totalcaount=@totalcount+@addcount;

No problem doing this in the same template, but how can I do this across Masterpage and belonging paragraph templates (all on same page off course)

 

BR

 

HAns


Replies

 
Nicolai Pedersen
Reply

You can use @ViewBag.TotalCount = 123 and access that from any template.

ViewBag is a Dynamic, so add any property you want.

 

You must be logged in to post in the forum