I have a complex View (cshtml) in my MVC3 project. Depending on different variables, the parts of this code must be shown in a different order. How can I separate blocks of Razor/HTML code and “include” them at the proper position?
Looking for something like that:
@{ CODEBLOCK 1
...
}
@{ CODEBLOCK 2
...
}
@if (bla==1) {
include CODEBLOCK 1
include CODEBLOCK 2
} else {
include CODEBLOCK 2
include CODEBLOCK 1
}
I don’t want to use HtmlPartial, since I don’t want to pass all vars, the model and other stuff to it.
You can use helper methods:
As a bonus, it’s type safe and allows arguments.