razor - 如何在 Visual Studio 2015 中编写多行属性?

标签 razor visual-studio-2015

最新版本的 Visual Studio 2015 使我们的整个 cshtml 标记处于非常脆弱的状态。很多时候,我们的属性值超出了可用宽度,我们需要将属性拆分为多行,以使代码更具可读性。

示例:宽数据绑定(bind)

<div data-bind="someBinding: { hasErrors: bindingObject.HasErrors(duration), hasWarnings: bindingObject.HasWarnings(duration), parameterKey: bindingObject.SelectedObjectKey }, anotherBinding: value, anotherBinding2: value2, AndSoOn: yaddayadda.the.point.is.this.can.get.really.long">

回到 VS 2010/2013,如果我们开始只是在属性值中放入回车符来将其分解,设计器通常将不再正确解析 html,并且此后的 DOM 元素将不再有效......例如 table 坏了。

因此我们发现,通过将属性值封装在 @("...") 中实际上可以让设计器顺利运行。

示例:使用 @() 属性绑定(bind)

<div data-bind="@("someBinding: { " +
    "hasErrors: bindingObject.HasErrors(duration), " +
    "hasWarnings: bindingObject.HasWarnings(duration), " +
    "parameterKey: bindingObject.SelectedObjectKey }, " +
    "anotherBinding: value, " +
    "anotherBinding2: value2, " + 
    "AndSoOn: yaddayadda.the.point.is.this.can.get.really.long")">

好消息是 IDE 甚至可以帮助扩展这个字符串,当页面重新格式化时它会很高兴并且 DOM 状态良好。服务器将获取此 C# 字符串并将其渲染到生产中的单行,一切都很好...

直到我们升级。 VS2015 似乎讨厌这一点,但原因完全不同。现在它会显示整个内容,并且工具提示显示“缺少属性名称”。当页面重新格式化时,一切都会变得糟糕......

enter image description here

所以我在这里走在玻璃上。这是某种错误还是有答案,因为我们有一个庞大的代码库,不想重构此属性格式。

想法?

最佳答案

Visual Studio 2015 Update 1 包含此问题的解决方案。

关于razor - 如何在 Visual Studio 2015 中编写多行属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33681156/

相关文章:

asp.net-mvc-3 - 在 razor 中使用 @if 时出现错误

c# - 在按钮中检测到 ActionLink 存在潜在危险的 Request.Path 值

c# - Linq 扩展方法在 Visual Studio 2015 立即窗口中不可用

c# - 插入字符串 c# 6.0 和 Stylecop

typescript - 如何使用 VSIX 中的 GetSyntaxRoot 获取 Typescript 作为 FileCodeModel 或 (Roslyn) 文档

asp.net - 将字符串传递到MVC4中的局部 View

asp.net-mvc - ASP.NET View 中的区域?

c# - 上传文件并过滤其扩展名

java.lang.NoClassDefFoundError : com/android/utils/ILogger into visual studio 2015 错误

c++ - 如何检查线程是否为 NULL