On my main page, I have the code @{Html.RenderPartial("_Partial1.cshtml");}
, and on my Partial, I have an HTML string:
@{ // The string is actually dynamic, not static. This is here for simplicity string abc="<div class=\"error\">abc</div>"; } @abc
I want to output abc
with some CSS error styles, but I actually got <div class="error">abc</div>
- of course, no styles there. How do I make it interpreted as HTML source code and not a string?
You can use the Html. Raw() method for that.
The ActionLink() and DisplayNameFor() are extension methods included in the HtmlHelper class. The HtmlHelper class generates HTML elements. For example, @Html.
The Html. Raw Helper Method is used to display HTML in Raw format i.e. without encoding in ASP.Net MVC Razor. Configuring Bundles. Please refer the following article for complete information on how to configure Bundles in ASP.Net MVC project. Using Bundles (ScriptBundle) in ASP.Net MVC Razor.
Render actions are methods that the view calls back in the controller. A strong design point about MVC is the neat separation of controller and view. In this regard, render actions just break this separation. Render actions are effective to use; balancing design with effective solutions is the developer's job.
You can use the Html.Raw()
method for that.
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