Last active
August 21, 2017 22:24
-
-
Save celston/dcc16a8768a12c3bd0ee4f4e15cadd02 to your computer and use it in GitHub Desktop.
MVC Razor Dynamic Sections
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta name="viewport" content="width=device-width" /> | |
<title>_Layout</title> | |
</head> | |
<body> | |
<div> | |
<ul> | |
@foreach (var tab in ((List<Tuple<string, string>>)ViewBag.Tabs)) | |
{ | |
<li>@tab.Item2</li> | |
} | |
</ul> | |
@foreach (var tab in ((List<Tuple<string, string>>)ViewBag.Tabs)) | |
{ | |
<div>@RenderSection("Tab" + tab.Item1)</div> | |
} | |
@RenderBody() | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@{ | |
ViewBag.Title = "Index"; | |
Layout = "~/Views/Shared/_Layout.cshtml"; | |
ViewBag.Tabs = new List<Tuple<string, string>>() | |
{ | |
new Tuple<string, string>("Red", "Red"), | |
new Tuple<string, string>("Yellow", "Yellow"), | |
new Tuple<string, string>("Blue", "Blue"), | |
new Tuple<string, string>("Green", "Green") | |
}; | |
} | |
@section TabRed { | |
<p>The quick brown fox...</p> | |
} | |
@section TabYellow { | |
<p>...jumped over...</p> | |
} | |
@section TabBlue { | |
<p>...the lazy dog.</p> | |
} | |
@section TabGreen { | |
<p>The End</p> | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@{ | |
ViewBag.Title = "Index"; | |
Layout = "~/Views/Shared/_Layout.cshtml"; | |
ViewBag.Tabs = new List<Tuple<string, string>>() | |
{ | |
new Tuple<string, string>("1", "One"), | |
new Tuple<string, string>("2", "Two"), | |
new Tuple<string, string>("3", "Three") | |
}; | |
} | |
@section Tab1 { | |
<p>The quick brown fox...</p> | |
} | |
@section Tab2 { | |
<p>...jumped over...</p> | |
} | |
@section Tab3 { | |
<p>...the lazy dog.</p> | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment