Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write multiline attributes in Visual Studio 2015?

The latest releases of Visual Studio 2015 has left our entire cshtml mark-up in a very fragile state. Many times we have attribute values that exceed a usable width and we need to split the attribute up across multiple lines to make the code more readable.

Example : wide data-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">

Back in VS 2010/2013 if we starting just putting carriage returns within the attribute value to break it up the designer would usually no longer parse the html appropriately and DOM elements following this would no longer be valid...such as a broken table.

So we found that by encapsulating the attribute value within @("...") would actually allow the designer to function smoothly.

Example : with @() attribute binding

<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")">

Well, the good news here is the IDE would even help with expanding this string and when the page reformatted itself it would be happy and the DOM was in great shape. The server would take this blob of C# string and render it to a single line in production and all was good...

Until we upgraded. VS2015 seems to detest this, but for entirely different reasons. Now it squiggles the entire thing and the tooltip says 'Missing Attribute Name'. When the page reformats it botches everything...

enter image description here

So I'm walking on glass here. Is this some sort of bug or is there an answer, cause we've got a big code base that doesn't want to go through having to refactor this attribute formatting.

Thoughts?

like image 459
beauXjames Avatar asked Oct 31 '22 15:10

beauXjames


1 Answers

Visual Studio 2015 Update 1 contains a resolution to this problem.

like image 136
beauXjames Avatar answered Jan 04 '23 15:01

beauXjames