Skip to content

Instantly share code, notes, and snippets.

@nul800sebastiaan
Forked from greystate/first-attempt.cshtml
Created August 10, 2011 18:57
Show Gist options
  • Save nul800sebastiaan/1137798 to your computer and use it in GitHub Desktop.
Save nul800sebastiaan/1137798 to your computer and use it in GitHub Desktop.
Raz0r kerfluffle
@helper RenderCountryOptions() {
<option>Choose a country...</option>
@foreach(var region in @Model.XPath("/root/Website/CountryList/CountryList[Country[not(active = 0)]]"))
{
<optgroup label="@region.Name">
@foreach(var country in @region.Children)
{
<option>@country.Name</option>
}
</optgroup>
}
}
// This one says:
// Unexpected "foreach" keyword after "@" character. Once inside code, you do not need to prefix constructs like "foreach" with "@".
@helper RenderCountryOptions() {
<option>Choose a country...</option>
foreach(var region in @Model.XPath("/root/Website/CountryList/CountryList[Country[not(active = 0)]]"))
{
<optgroup label="@region.Name">
foreach(var country in @region.Children)
{
<option>@country.Name</option>
}
</optgroup>
}
}
// The name 'country' does not exist in the current context
@helper RenderCountryOptions() {
<option>Choose a country...</option>
foreach(var region in @Model.XPath("/root/Website/CountryList/CountryList[Country[not(active = 0)]]"))
{
<optgroup label="@region.Name">
@foreach(var country in @region.Children)
{
<option>@country.Name</option>
}
</optgroup>
}
}
// Hmmm... yes. OK - I get that, but it's weird for me...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment