Hugh Jones
Hugh Jones

Reputation: 2694

How to debug javascript in cshtml

I have a .cshtml file of the following format (apologies if my JavaScript terminology is a bit loose)

@model SomeViewModel
@{ Response.ContentType = "application/x-javascript"; }

$(function() {
         // Javascript event handler code here
    }
});

$(function ($) {
        // Javascript JQuery.DatePicker extensions here
    }
});

I am fairly sure that there is a bug that needs fixing in the second JS block, but I am struggling to debug it. I am using Chrome.

The picture is somewhat complicated by the fact that there exists a MyDatepicker.js file elsewhere in the solution with the exact same javascript, and a MyDatepicker.min.js which appears at runtime and can be debugged (just about).

So


following the advice given below, I find the following class.

public class MyDatePickerController : Controller
{
    // GET: /jquery.mydatepicker.js
    [Minify]
    [HttpGet]
    public ActionResult Index()
    {
        MyDatePickerViewModel model = new MyDatePickerViewModel(); 

        return View(model);
    }
}

which appears to explain how the javascript gets minified.

Given that there is a MyDatePicker.js file as well as the code in the .cshtml file, I am still unsure which copy of the javascript gets loaded. I will edit one of them, take out the minify and see which gets loaded.


Now that I have located the reason the script was being minified I have been able to establish for certain that the javascript being executed was that from the razor file (.cshtml)

Upvotes: 0

Views: 3492

Answers (1)

Vignesh Pandi
Vignesh Pandi

Reputation: 359

Check your bundleconfig file, MyDatepicker.min.js might be bundled with other js files.

Upvotes: 1

Related Questions