Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC View Code Formatting - braces <% } %>

Does anyone know how to configure visual studio to correctly format code segments within a View

This annoys the crap outta me!:

<select>
<%
foreach(Height height in ViewData.Model.Heights)
{%>
<option value="<%=height.ID %>"><%=height.Value%></option>
<%
}%>
</select>

It should be like this:

<% foreach(Height height in ViewData.Model.Heights) { %>
    <option value="<%=height.ID %>"><%=height.Value%></option>
<% } %>
</select>

I can fix it manually but whenever I reformat, or change some of the code close to the braces it screws up again!

like image 805
reach4thelasers Avatar asked Nov 25 '09 13:11

reach4thelasers


People also ask

What is @: In Cshtml?

This operator is useful in conjunction with other Razor server side operators when you want to output something as a literal text. For example: @if (model. Foo) { @:Some text to be written directly. }

What is meaning of @: In .NET MVC?

Using @: to explicitly indicate the start of content We are using the @: character sequence to explicitly indicate that this line within our code block should be treated as content.

What is Razor in MVC why it is used?

Razor is a markup syntax that lets you embed server-based code into web pages using C# and VB.Net. It is not a programming language. It is a server side markup language. Razor has no ties to ASP.NET MVC because Razor is a general-purpose templating engine. You can use it anywhere to generate output like HTML.

Does MVC use Razor?

Razor is one of the view engines supported in ASP.NET MVC. Razor allows you to write a mix of HTML and server-side code using C# or Visual Basic.


1 Answers

After the auto formatting takes place hit cntrl-z, it will undo the auto-formatting only and not rearrange your code.

like image 188
John Farrell Avatar answered Oct 17 '22 10:10

John Farrell