How can I indent code in vbhtml razor files?

It drives me in a circle. I have been a VB.NET form developer for a long time, completely new to ASP.NET and completely new to MVC . I am creating vbhtml pages that use VB.NET Razor syntax, and I seem to be constantly struggling with a UI that is trying to defer my code incorrectly. Take the following template-based example for the new Razor view:

 @Code Layout = Nothing End Code <!DOCTYPE html> <html> <head> <title></title> </head> <body> <div> @If True Then @<ul> @For x = 1 To 2 Next </ul> End If '<-- Randomly indented too far </div> </body> </html> 

In the above example, as soon as I press return after Next , End If , the two lines below randomly jump the two tabs forward, where they should be from. In other examples, I ended up in a circle where clicking one line at the right place throws another line out of position and vice versa.

I am so annoyed at this moment, I would be happy to completely turn off auto-scooping and handle it myself, but I can’t even figure out how to do it! Following the tips in another thread, I turned off the indentation for the HTML pages, but all that stops is the indentation of the HTML tags - the blocks of code are still sliding all over the place.

I thought the extension might cause the problem, but I disabled them all and restarted, and the problem remained. Am I doing something fundamentally wrong? I find it hard to believe that Microsoft will release something so poor that it seems more likely, I just do not use it correctly.

+6
source share
2 answers

I found a solution (by fashion) on another question (I really looked for work before posting this question and could not find anything): Why does Visual Studio code formatting work correctly for Razor markup?

Essentially, the solution seems to ensure that your code uses spaces instead of tabs for spaces. By increasing the overall page size due to the increase in spaces, it reduces the problem (although it does not completely eliminate it). In a related topic, someone who seems to be related to Microsoft admitted that this is indeed a bug related to overlapping formats for HTML and VB.NET, which they hope to improve in the new version. I reduced it to 2 spaces per indent to reduce the effect of bandwidth.

Thanks to the guys who contributed.

+2
source

The best alternative here (instead of using spaces for tabs) is to change the indentation of the block for HTML and C # / VB to "Block" instead of "Smart". This is not a complete solution, but IMO is much less painful than using spaces!

0
source

Source: https://habr.com/ru/post/902391/


All Articles