john
john

Reputation: 21

How to add white space in ASP. NET MVC view

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?

Upvotes: 2

Views: 13509

Answers (7)

Mubarak
Mubarak

Reputation: 31

In my application I have used a space after the link's name ("Details ") as shown here

 @Html.ActionLink("Details ","Details", new { Variable_ID = item.VIP_ID})
                        @Html.ActionLink("Edit", "Edit",  new { Variable_ID = item.VIP_ID })

so my links will look like this: Details Edit, instead of DetailsEdit. You can also put a separation bar like this "Details | ", so you can have Details | Edit

Upvotes: 1

NatalyaKst
NatalyaKst

Reputation: 333

One more variant:

@(string.Format("{0} {1}", item, item))

Upvotes: 0

Avijit Nanda
Avijit Nanda

Reputation: 1

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.

Upvotes: 0

ankitkanojia
ankitkanojia

Reputation: 3122

//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>
}

Upvotes: 0

Subhash Saini
Subhash Saini

Reputation: 274

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

Insert "&nbsp;" to add more blank spaces

Upvotes: 0

Mihai Alexandru-Ionut
Mihai Alexandru-Ionut

Reputation: 48367

You can use pre tag , which defines preformatted text.

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

Upvotes: 2

Harj Sohal
Harj Sohal

Reputation: 141

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

Upvotes: 1

Related Questions