Flea
Flea

Reputation: 11284

Javascript function collapse in Visual Studio 2012 does not work with jquery ajax syntax

I've found this annoying problem in Visual Studio 2012 where the IDE is not collapsing JavaScript functions that contain certain syntax with Ajax.

The following code if you put in VS2012 inside a .cshtml file will not allow you to collapse the function that has the jquery syntax:

VS 2012 Sample Code

function HelloWorld()
{

}

function GoodByeWorld()
{

}

function UpdatePatientDiagnosis()
{
if (ValidateDiagnosisFields() == false)
    return;

var request = $.ajax({
    type: "POST",
    url: "@Url.Action("AjaxUpdatePatientDiagnosis", "Referral")",
    data: "{ CodeTypeId : \"" + $("#DiagnosisCodeType_Description option:selected").val() + "\"," +
          " Code: \"" + $("#Diagnosis_Code").val() + "\"," +
          " Description : \"" + $("#Diagnosis_Description").val() + "\" }",
    contentType: "application/json; charset=utf-8",
    dataType: "text"
});

request.done(function( msg ) 
{
    // Saves the rest of the form.
    $('#btnPatientSave').click();
});

request.fail(function( jqXHR, textStatus ) 
{
    ShowMessagePopup("Error", "An error occurred trying to update diagnosis.");
});

}

Here is a screen shot of the sample code in VS 2012 enter image description here

However, if you take that same sample code and put it in a web file in VS 2010, it collapses just fine. Here is a screen shot showing it collapsed:

enter image description here

For whatever reason, VS 2012 IDE does not like the syntax of request.done and request.fail.

This is just very annoying because I am working on a project that has thousands of lines of JS functions and I am unable to collapse the ones that have this particular jquery syntax. Any suggestions on how to restructure this in VS2012 to make it work?I tested in VS 2013 and it had the same problem.

Upvotes: 2

Views: 438

Answers (1)

Ctrl+M,Ctrl+O to collapse function body

Upvotes: 1

Related Questions