When typing code in a .aspx file (an MVC view in this case), Visual Studio applies two types of formatting, one to the regular html tag structure (which can be controlled from Tools->Options->Text Editors->Html) and another to content inside the <% %> tags.

I've run into two annoyances with the second type of automatic formatting, the <% %> content formatting.

首先是如何将新行添加到语句块:

如果我打这个:

<% if(condition) { %>
    ...
<% } %>

它会自动更正为:

<% if(condition) 
   { %>
    ...
<% } %>

如果这是一个错误,那么修正是正确的.cs文件,用于标记汤.我发现第一个aspx文件的可读性要高得多.有没有一种方法可以在不影响文件格式的情况下关闭此行为.cs文件?

第二,每当我写这样的东西:

<%=Html.ActionLink("Report","ListItems") %>

我找不到一种方法自动将其格式化为此格式(在适当的地方添加空格):

<%=Html.ActionLink("Report", "ListItems") %>

在代码中,你通常需要一个;或者}表示您已经完成了一行/一段代码,以便Visual Studio可以对其进行格式化.有没有办法给a&lt;%=表达方式?

CLARIFICATION

This question is about the formatting of code inside <% %> tags without affecting the formatting of regular C# source files. It says right in the first paragraph that I am completely aware of the Text Editors menu.

推荐答案

文本编辑器菜单是所有的,它不允许你做你想做的事情.右键单击aspx页面时,单击"格式化和验证…"然后点击按钮"标记特定选项…"每个客户机或服务器标记都会有一系列设置,但对于<;%则没有-标签.

至于问题的第二部分,Ctrl-E,D设置文档格式,但不插入所需的间距.

Asp.net相关问答推荐

目前不支持超过 65534 个段的跨区存档

我可以强制刷新我的样式表文件吗?

如何使用 javascript 获取 MVC 应用程序的基本 URL

HttpContext.Cache 过期

在视图 Mvc.net 中访问路由值

asp.net mvc 中的 RedirectToAction 用法

为什么我不能在 ASP.net MVC 中使用服务器控件?

Gridview ItemTemplate 中多个判断字段的最佳技术?

stream.CopyTo - 文件为空.网

显示单选按钮列表内联

IIS 10 上的 ASP.NET Core 404 错误

在asp.net mvc 3中实现FilterAttribute,IActionFilter和从ActionFilterAttribute继承有什么区别?

在 ASP.NET 中使用 MasterPages 时使用 JQuery 的正确方法?

如何强制 netwtonsoft json 序列化程序将 datetime 属性序列化为字符串?

MVC3 和实体框架

IISExpress 找不到使用 Visual Studio 2013 运行 localhost 的 ssl 页面

通过 CultureInfo 格式化字符串

如何在 asp.net 中实现Access-Control-Allow-Origin标头

Windows 身份验证在本地 IIS 7.5 上不起作用.错误 401.1

您的下一个 ASP.NET 项目的 Select 是什么:Web 窗体还是 MVC?