I have written an HtmlHelper Extension to format some content based some of our styles. The helpers render the content correctly when not enclosed within an if.
However, when I am trying to wrap them in a razor if statement, nothing is rendering, I suspect it has something to do with the Razor syntax that I am not doing correctly.
Code:
<div class="notice">
@if (DataModel.UserHasExpired)
{
Html.MyCustomNotificationBox("someparameter") // My helper Should render a div
}
</div>
If I place my notificationbox outside of the if, it works fine. I have also verified that the code is dropping into the block, but none of the markup is generated in the html when I inspect it.
I've tried appening a @ like so, and ending with a colon
@Html.MyCustomNotificationBox("somparameter");
I have even tried @Html.Raw(..with the above..) which completely errors out.
Any ideas?
We can use this HTML. RadioButton() Helper method using the class to define the HTML elements. This is the loosely typed expansion method function which we can define as input type to select the (<input type="radio" >) element in razor view.
The HtmlHelper class renders HTML controls in the razor view. It binds the model object to HTML controls to display the value of model properties into those controls and also assigns the value of the controls to the model properties while submitting a web form.
All Razor files end with . cshtml. Most Razor files are intended to be browsable and contain a mixture of client-side and server-side code, which, when processed, results in HTML being sent to the browser. These pages are usually referred to as "content pages".
Have you tried putting it in text
tags (those tags are not sending to client)?
@if (DataModel.UserHasExpired)
{
<text>@Html.MyCustomNotificationBox("somparameter")</text>
}
<p>
@if (true)
{
@Html.Hello("World")
}
</p>
Works Perfectly fine
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