我正在使用 Glimpse MVC4 版本 1.2.0。
我注意到当我在浏览器中打开 Glimpse UI 时,“模型绑定”选项卡被禁用。我看不到如何启用它。阅读Glimpse 文档显示您可以忽略选项卡
<glimpse defaultRuntimePolicy="On" endpointBaseUri="~/Glimpse.axd">
<tabs>
<ignoredTypes>
<add type="{Namespace.Type, AssemblyName}"/>
</ignoredTypes>
</tabs>
</glimpse>
但我的 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>
所有其他选项卡均已启用。有人可以建议禁用此选项卡的原因吗?
编辑:我注意到“会话”选项卡也被禁用。
啊好的,我添加一个Session["Testing"] = "123"
呼叫后,“会话”选项卡现在已启用。尽管如此,仍然无法启用“模型绑定”选项卡。这是我在回发中的视图代码:
[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;
}
}
使用 PRG 的想法,我重新编写了我的代码,如下所示:
[HttpPost]
public ActionResult Index([ModelBinder(typeof(MyModelBinder))]HomeIndexViewModel viewModel)
{
return this.RedirectToAction("SaveSuccess");
}
public ActionResult SaveSuccess(HomeIndexViewModel viewModel)
{
return this.View();
}
我遇到的问题是,在“历史记录”选项卡中,当我检查“SaveSuccess”请求时,我可以看到“模型绑定器”已启用,并显示正在使用的 DefaultModelBinder。但是,我使用自定义模型绑定器的索引请求未启用该选项卡。