Are variables I define in a shared layout _Layout.cshtml within scope of a View page?
_Layout.cshtml varibles:
@{
ViewBag.url = "http://www.website.com/site/";
}
Index.cshtml:
<a class="continue" href="@ViewBag.url/our-vision/">Continue</a>
This outputs: /our-vision/
You could try answer from this question: How do I set ViewBag properties on _ViewStart.cshtml?
Set (Note: code is for _ViewStart, not for _Layout)
@{
PageData["message"] = "Hello";
}
Get
<h2>@PageData["message"]</h2>
OR
Create more interesting solution: How to set ViewBag properties for all Views without using a base class for Controllers?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With