Mandar Jogalekar
Mandar Jogalekar

Reputation: 3281

Razor view engine pass data from layout to content

I am using razor view engine outside of mvc framework. Before you wonder, there are some project specific reasons.

So While adding pages, I add .cshtml layout and content page. The question is without mvc framework(which takes out possibility of viewback,tempdata) , How can I access variable/data on layout page in content cshtml page? For example: If I have in layout

@data=DB.GetData()

Then Can I have @data accessible in content .cshtml page?

Upvotes: 0

Views: 732

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038730

You can use the PageData dictionary:

@{PageData["data"] = DB.GetData();}

or if you are a fan of dynamic stuff:

@{Page.data = DB.GetData();}

Upvotes: 1

Related Questions