html – How to add white space in ASP. NET MVC view-ThrowExceptions

Exception or error:

Is there a way to add white space in MVC while using variables? for example foreach(item in collection) {@item @item}. How to make a blank space something like ” ” in it?

How to solve:

You can use pre tag , which defines preformatted text.

foreach(item in collection) {
   <pre>@item @item</pre>
}

###

have you tried &nbsp; this can be repeated i.e. &nbsp;&nbsp; you can do line breaks with <br />

###

<span> &nbsp; &nbsp; &nbsp;</span>

Insert “&nbsp;” to add more blank spaces

###

//This will work for sure, as MVC C# using razor syntax then you just need to put space between those two only  
foreach(var item in collection) {
    <span>@item @item</span>
}

###

If you wish to add single space between item:

foreach(item in collection) 
 {
     <p>@item @item</p>
 }

But you will have better flexibility if you wrap it in a HTML element like div or span,
and then add padding/margin to the element using CSS.

foreach(item in collection) 
{
    <div class="user-defined-classname">@item</div>
    <div class="user-defined-classname">@item</div>
}

In CSS

.user-defined-classname{
    padding-left|right|top|bottom: 10px
}

Suggestion:
The “Views” folder is specifically meant to just contain your view files (i.e. .cshtml files).

Try adding your CSS file to a folder in the root of the ASP.NET project. Often, this folder is named “Content”, but you can rename it as “Styles” or something else. Then you can load your CSS file from within a view using a link tag:

<link href="~/Content/styles.css" rel="stylesheet" type="text/css" />

This may help.

Leave a Reply

Your email address will not be published. Required fields are marked *