Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Razor - How to prevent unwanted line break in view source when @{} or @() was used?

Whenver I use @{ } or @( ) in the webpage and run it from Visual Studio, then in the web-browser, i noticed in the view source are are line break before the @{ syntax and another line break after the } syntax.

Is there a way to prevent line break so the view source become easier to read?

Thanks...

like image 612
fletchsod Avatar asked May 22 '13 23:05

fletchsod


People also ask

How do you stop a line break?

Use white-space: nowrap; or give that link more space by setting li 's width to greater values. I prevented line break in li items using display: inline; . Maybe this will also help others with similar problems. Its important to be careful with display: inline as it can have side effects.

How do you stop a line break in HTML?

<nobr> The NOBR element prevents line breaks.

How do you stop a new line in CSS?

The white-space property has numerous options, all of which define how to treat white space inside a given element. Here, you have set white-space to nowrap , which will prevent all line breaks.


1 Answers

I don't think there is anything you can do regarding the line breaks. The formatting is as per source file after its been compiled and rendered from the server side.

The effect to the end user in terms of layout is nothing as its not a html line break: <br>

You can put server side code in-line as per the example below which will stop the line spacing:

a<br/>@{ /*some code 1 that does not produce a line break*/}
b<br />
c<br />
@{ 
    /*some code 2 that does produce line breaks*/
}
d<br />
e<br />

this will produce the following:

a<br />
b<br />
c<br />

d<br />
e<br />
like image 174
SkyBlues87 Avatar answered Dec 01 '22 19:12

SkyBlues87