Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I insert spaces within a razor Code block?

VS2013, MVC5, Razor, VB

I want spaces in front of the word 'Answered'. How do I force spaces into the following Razor code block?

@Code If Model.DisplayAnsweredFlag Then
  @If Model.Answered Then
    @Html.Raw("Answered")
   End If
 End If
End Code

In html.raw(), spaces by themselves or spaces in of front text don't seem to get coded into the page. But I also can't use '&nbsp' or '@&nbsp' in a Code Block because it's incorrect syntax.

If I'm coding with a poor technique, please advise, or if there is a different way to get the spaces in, please advise.

like image 979
Alan Avatar asked Feb 02 '15 17:02

Alan


1 Answers

AndyBuk gave the answer here:
https://forums.asp.net/t/1772048.aspx?How+to+use+no+break+space+HTML+character+inside+if+brackets+in+a+view+

In that link he writes:

The introduction to Razor syntax at:
http://www.asp.net/web-pages/tutorials/basics/2-introduction-to-asp-net-web-programming-using-the-razor-syntax is quite useful.
To force html output for your string, you may use <text> to Block or @: as a Prefix.

@if (condition)
{
    <text>&nbsp;</text>
    @:&nbsp;
}
like image 106
MikeTeeVee Avatar answered Oct 22 '22 04:10

MikeTeeVee