How to turn off Auto correct for braces and coded elements in a Visual Studio MVC View
I am using Visual Studio 2010, but this applies to VS 2008 as well.
In my MVC views I prefer to write my coded elements as follows:
<% if (somecondition) { %>
<p>something</p>
<% } else { %>
<p>something else</p>
<% } %>
This just looks more readable to me than the following which is what VS auto corrects my code to look like:
<% if (somecondition)
{ %>
<p>something</p>
<%}
else
{ %>
<p>something else</p>
<%} %>
I usually stop my work to format the code back into the fashion that I prefer, but am getting tired of this. I love the auto-correcting in VS, but want this to cea开发者_如何学编程se only in my views, and only for what I describe above. Is this possible?
Right click within your view then:
Pick Formatting and Validation
Expand: C# -> Formatting -> Newlines
Then uncheck 'Place open brace on new line for control blocks'
Yeah, it's annoying. Here's how to turn it off:
- Go to
Tools
->Options
- In the
Text Editor
option look for t`HTML1 and expand the node. - In the
Formatting
option, turn off allAutomatic formatting options
.
Alternatively, in the same dialog, you can configure the formatting for each specific tag. Just click on the Tag Specific Options...
button.
精彩评论