Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to set breakpoints in razor views with servicestack?

I am trying out the new razor view stuff in service stack, and I have this view:

@inherits ServiceStack.Razor.ViewPage<ServiceStackRazorCrud.Api.UserPageResourceResponse>
@{
    var m = Model;  // <-- I have a breakpoint in this line.
    var req = Request; 
    var res = Response;
}

When I set a breakpoints and run the application (console application) I can see that the view is compiled but the debugger does not break when I request the view in the browser. I assume that this is because the views are compiled dynamically at application start or something like that. Is it possible somehow to get the breakpoints to work?

like image 965
Stig Schmidt Nielsson Avatar asked Sep 22 '12 06:09

Stig Schmidt Nielsson


1 Answers

AFAIK it's not possible to debug views this way (currently using 3.9.43, later version I believe has better diagnostics for compilation errors).

Try and keep view code simple, restricted to simple loops/rendering and using extension methods on DTO's for any complex logic/processing, which do allow debugging. You might also consider utilizing logging, or a simple Debug extension method:

using ServiceStack.Html;
public static class HtmlHelperExtensions
{
    public static bool IsDebug(this HtmlHelper htmlHelper)
    {
    #if DEBUG
        return true;
    #else
        return false;
    #endif
    }
}

@using ServiceStack.Text
@inherits ServiceStack.Razor.ViewPage<ServiceStackRazorCrud.Api.UserPageResourceResponse>
@{
    var m = Model;  
}

@if (this.Html.IsDebug())
{
    <div class="debug">@(this.Model == null ? "m == null" : Model.Dump())</div>
}
like image 63
Gavin Faux Avatar answered Sep 26 '22 02:09

Gavin Faux