Question

I'm using Glimpse MVC4 version 1.2.0.

I notice that the "Model Binding" tab is disabled when I open the Glimpse UI in my browser. I can't see how to enable it. Reading the Glimpse docs reveals that you can ignore tabs

<glimpse defaultRuntimePolicy="On" endpointBaseUri="~/Glimpse.axd">
    <tabs>
        <ignoredTypes>
            <add type="{Namespace.Type, AssemblyName}"/>
        </ignoredTypes>
    </tabs>
</glimpse>

But I have none of that in my web.config:

<?xml version="1.0" encoding="utf-8"?>
<!--
  For more information on how to configure your ASP.NET application, please visit
  http://go.microsoft.com/fwlink/?LinkId=169433
  -->
<configuration>
  <configSections>
    <section name="glimpse" type="Glimpse.Core.Configuration.Section, Glimpse.Core" />
  </configSections>
  <appSettings>
    <add key="webpages:Version" value="2.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="PreserveLoginUrl" value="true" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
  </appSettings>
  <system.web>
    <httpRuntime targetFramework="4.5" />
    <compilation debug="true" targetFramework="4.5" />
    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages" />
      </namespaces>
    </pages>
    <!-- Glimpse: This can be commented in to add additional data to the Trace tab when using WebForms
        <trace writeToDiagnosticsTrace="true" enabled="true" pageOutput="false"/> -->
    <httpModules>
      <add name="Glimpse" type="Glimpse.AspNet.HttpModule, Glimpse.AspNet" />
    </httpModules>
    <httpHandlers>
      <add path="glimpse.axd" verb="GET" type="Glimpse.AspNet.HttpHandler, Glimpse.AspNet" />
    </httpHandlers>
  </system.web>
  <system.webServer>
    <handlers>
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" />
      <remove name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" />
      <remove name="ExtensionlessUrlHandler-Integrated-4.0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_32bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness32" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-ISAPI-4.0_64bit" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" modules="IsapiModule" scriptProcessor="%windir%\Microsoft.NET\Framework64\v4.0.30319\aspnet_isapi.dll" preCondition="classicMode,runtimeVersionv4.0,bitness64" responseBufferLimit="0" />
      <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="GET,HEAD,POST,DEBUG,PUT,DELETE,PATCH,OPTIONS" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
      <add name="Glimpse" path="glimpse.axd" verb="GET" type="Glimpse.AspNet.HttpHandler, Glimpse.AspNet" preCondition="integratedMode" />
    </handlers>
    <validation validateIntegratedModeConfiguration="false" />
    <modules>
      <add name="Glimpse" type="Glimpse.AspNet.HttpModule, Glimpse.AspNet" preCondition="integratedMode" />
    </modules>
  </system.webServer>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <glimpse defaultRuntimePolicy="On" endpointBaseUri="~/Glimpse.axd">
    <!-- If you are having issues with Glimpse, please include this. It will help us figure out whats going on.
      <logging level="Trace" /> -->
  </glimpse>
</configuration>

All the other tabs are enabled. Could someone suggest a reason why this tab is disabled?

EDIT: I notice that the "Session" tab is also disabled.

Ah OK, after I added a Session["Testing"] = "123" call, the "Session" tab is now enabled. Still can't get the "Model Binding" tab enabled though. Here's my view code on the postback:

[HttpPost]
public ActionResult Index([ModelBinder(typeof(MyModelBinder))]HomeIndexViewModel viewModel)
{
    return this.View(viewModel);
}

public class MyModelBinder : IModelBinder
{
    public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        var viewModel = new HomeIndexViewModel();

        viewModel.Name = "From model binder.";
        return viewModel;
    }
}

Using the PRG idea, I re-wrote my code like so:

[HttpPost]
public ActionResult Index([ModelBinder(typeof(MyModelBinder))]HomeIndexViewModel viewModel)
{
    return this.RedirectToAction("SaveSuccess");
}

public ActionResult SaveSuccess(HomeIndexViewModel viewModel)
{
    return this.View();
}

The problem I have is that, in the History tab, I can see that "Model Binder" is enabled when I inspect the "SaveSuccess" request, adn that shows the DefaultModelBinder in use. However, my Index request, where I use my custom model binder, does not enable the tab.

Was it helpful?

Solution

The Model Binding tab in Glimpse will become enabled when there is Model Binding activity for a given page request. If there is no model binding activity, the tab will appear disabled.

Another common issue with the model binding tab is the use of the PRG (POST REDIRECT GET) pattern.

If the action method that contains the model binding redirects a user, than Glimpse will show the last request (which is the GET), effectively hiding the model binding activity. You can use the History tab in Glimpse to select the previous request (the original POST) and see the model binding data.

Finally, Glimpse can't help if you use ModelBinderAttribute (at least currently). Instead use ModelBinders.Binders.Add() or better yet an IModelBinderProvider to register your custom model binder. Glimpse picks up model binders registered in those ways.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top