Can I make Visual Studio place curly braces on the

2019-03-09 19:13发布

In Visual Studio while designing MVC views (in .aspx or .ascx files) I often use if statements. When I auto-format (Ctrl-K,D), VS wraps the braces in this really ugly and hard to read way:

<% if (Model.UserIsAuthenticated)
   { %>
       (some HTML goes here...)
<% } %>

Is there any way to make Visual Studio auto-format like this instead:

<% if (Model.UserIsAuthenticated) { %>
       (some HTML goes here...)
<% } %>

Or is there a better way to do this? I don't want to use Razor quite yet, but it looks like it would solve my problem. I'm using VS2010 with Resharper 5, if that helps.

2条回答
在下西门庆
2楼-- · 2019-03-09 19:32

the formatting is handled by individual plugins, for js you can use the following setting:

// Defines whether an open brace is put onto a new line for functions or not.
"javascript.format.placeOpenBraceOnNewLineForFunctions": true,
查看更多
爷、活的狠高调
3楼-- · 2019-03-09 19:33

Under ToolsOptionsText EditorC#FormattingNew Lines are the rules for the open brace on each case (new methods, control blocks, etc), maybe you can find the one you want there.

enter image description here

查看更多
登录 后发表回答