开发者

How to turn off Auto correct for braces and coded elements in a Visual Studio MVC View

开发者 https://www.devze.com 2023-01-11 05:41 出处:网络
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:

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:

  1. Go to Tools -> Options
  2. In the Text Editor option look for t`HTML1 and expand the node.
  3. In the Formatting option, turn off all Automatic formatting options.

Alternatively, in the same dialog, you can configure the formatting for each specific tag. Just click on the Tag Specific Options... button.

0

精彩评论

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

关注公众号