How to debug c# code being called by JqGrid?

371 views Asked by At

I have some code like this:

@{
ViewBag.Title = "Home";

var grid = new JqGridHelper<Project>("projects",
dataType: JqGridDataTypes.Json,
methodType: JqGridMethodTypes.Post,
pager: true,
rowsNumber: 10,
sortingName: "Id",
sortingOrder: JqGridSortingOrders.Asc,
subgridEnabled: true, 
url: Url.Action("ProjectsByUser"), <---- Here
etc...

By my understanding, url: URL.Action("FunctionName") will call a function that exists somewhere in my project with the name "FunctionName". All I want to do is look at the variables in the function while its running, but placing a breakpoint in VS doesn't work. So how would I go about doingnspect is executed, but the debugger only shows the code of scripts being executed, not the that? I've tried debugging with Chrome by setting up breakpoints before the code I want to in c# code.

1

There are 1 answers

5
Eric J. On

I'm not sure why placing a breakpoint would not work (assuming you start running the project in the debugger, and the breakpoint is in the right place).

You can add the following code to the method you wish to debug:

#if DEBUG
System.Diagnostics.Debugger.Break();
#endif

That will force a debug break, and prompt to attach a debugger if none is currently attached.

Remember to remove the code after you are done troubleshooting. While the #if DEBUG will prevent that code from being part of a release build, you don't want to risk accidentally shipping a DEBUG build that contains that break instruction.