开发者

Prevent visual studio auto-indenting C# code in ASP.Net MVC Views

I am in a view开发者_StackOverflow社区 editing HTML and I may for example need one line of C# code inside <% %> tags..

If that C# code contains a bracket like { or } after I press enter or complete the command, VS automatically spreads the line over 2 lines to kind of auto-indent the brackets.

It's really annoying because I am not in code view, I just want my view to look super clean and therefore keep the C# indentation exactly how I typed it in.

Any idea how to disable this???

Many thanks..


Every Visual Studio auto-indent operation is being saved in the Undo history. This means that if you press Ctrl+Z (undo) immediately after the auto-indent, it will be canceled and the code will be reverted to the initial indentation. This undo operation will not affect any characters that you have entered, only the auto-indentation.

It is still annoying, since it requires an additional keyboard input, but for many situations it is a good enough workaround.


Yeah, I've experienced that too... Hate it when VS does that. But the only way to do it, that I know of, is disabling C#'s "Automatically format completed block on }"...

Go to Tools | Options | Text Editor | C# | Formatting | General and uncheck it.

BUT you will lose this feature for all C# code (not only in views)...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜