I've been trying to get a dynamic button slider, but I can't even get a simple conditional to print anything. I thought @Html.Raw was the best way to print HTML from within Razor. Am I missing something? Document.write isn't even recognized. Any thoughts on how I should pass static HTML here, yet alone page variables?
<div class="content">
@{var localselected = 1;
if (localselected == 1){
Html.Raw("test1");
}
else if (localselected == 2){
Html.Raw("test2");
Html.Raw(page2);
}
}
</div>
You just need to wrap the localselected
variable in @{}, like below:
@{var localselected = 1;}
@if (localselected == 1)
{
@Html.Raw("test1")
}
else if (localselected == 2)
{
@Html.Raw("test2")
@Html.Raw(@Html.Partial("Page")).ToString()
}
Note: Page
is a parital view. using @Html.Raw(@Html.Partial("Page")).ToString()
it'll print out all of html elements and content.
There are two options available to print content from server code inside Razor view
Please refer http://weblogs.asp.net/scottgu/archive/2010/12/15/asp-net-mvc-3-razor-s-and-lt-text-gt-syntax.aspx
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