如何保证HTTPContext有价值?
我正在构建 MVC Storefront 的一个版本。我有两个主题,一个是标准 ui,另一个是管理 ui。我有一些 HTML Helper 方法,它们将 .ascx 文件传递到 .aspx 文件,就像示例一样,但没有插件。所有的东西都适用于默认主题,但它们都不适用于管理主题。当 Html.SimpleActivityTypeList() 触发时,我总是遇到相同的错误。 Html.RenderPartial(“AdminLeftNav”) 将始终工作正常。
<asp:Content ID="Content3" ContentPlaceHolderID="NavContent" runat="server">
<% Html.SimpleActivityTypeList(); %>
<% Html.RenderPartial("AdminLeftNav"); %>
</asp:Content>
我已将如下方法添加到扩展类中。
public static void SimpleActivityTypeList(this HtmlHelper helper)
{
helper.RenderAction<CatalogController>(x => x.SimpleActivityTypeList());
}
正如我所说,这在默认主题中效果很好。 请帮忙?
Stack Trace:
[ArgumentNullException: Value cannot be null.
Parameter name: httpContext]
System.Web.Routing.RequestContext..ctor(HttpContextBase httpContext, RouteData routeData) +85
Microsoft.Web.Mvc.ViewExtensions.RenderRoute(HtmlHelper helper, RouteValueDictionary values) +367
Microsoft.Web.Mvc.ViewExtensions.RenderAction(HtmlHelper helper, Expression`1 action) +113
GrandGuide.Web.CMSExtensions.SimpleActivityTypeList(HtmlHelper helper) in C:\S3_Depot\S3_Dev\GrandGuide\GrandGuide.Web\Infrastructure\Helpers\CMSExtensions.cs:55
ASP.views_themes_admin_index_aspx.__RenderContent3(HtmlTextWriter __w, Control parameterContainer) in c:\S3_Depot\S3_Dev\GrandGuide\GrandGuide.Web\Views\Themes\Admin\Index.aspx:7
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Control.Render(HtmlTextWriter writer) +10
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
ASP.views_themes_admin_theme_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\S3_Depot\S3_Dev\GrandGuide\GrandGuide.Web\Views\Themes\Admin\Theme.Master:33
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Control.Render(HtmlTextWriter writer) +10
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Page.Render(HtmlTextWriter writer) +29
System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +71
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266
I am building a version of the MVC Storefront. I have two themes, one is the standard ui, and the other is the admin ui. I have some HTML Helper methods, which deliver .ascx files to the .aspx files just like the example, but without plug-ins. All the stuff works on the default theme, but none of it works in the admin theme. I always get the same error when the Html.SimpleActivityTypeList() fires. The Html.RenderPartial(“AdminLeftNav”) will always work fine.
<asp:Content ID="Content3" ContentPlaceHolderID="NavContent" runat="server">
<% Html.SimpleActivityTypeList(); %>
<% Html.RenderPartial("AdminLeftNav"); %>
</asp:Content>
I have added a method as below to an extension class.
public static void SimpleActivityTypeList(this HtmlHelper helper)
{
helper.RenderAction<CatalogController>(x => x.SimpleActivityTypeList());
}
And as I said this works fine in the default theme.
Please Help?
Stack Trace:
[ArgumentNullException: Value cannot be null.
Parameter name: httpContext]
System.Web.Routing.RequestContext..ctor(HttpContextBase httpContext, RouteData routeData) +85
Microsoft.Web.Mvc.ViewExtensions.RenderRoute(HtmlHelper helper, RouteValueDictionary values) +367
Microsoft.Web.Mvc.ViewExtensions.RenderAction(HtmlHelper helper, Expression`1 action) +113
GrandGuide.Web.CMSExtensions.SimpleActivityTypeList(HtmlHelper helper) in C:\S3_Depot\S3_Dev\GrandGuide\GrandGuide.Web\Infrastructure\Helpers\CMSExtensions.cs:55
ASP.views_themes_admin_index_aspx.__RenderContent3(HtmlTextWriter __w, Control parameterContainer) in c:\S3_Depot\S3_Dev\GrandGuide\GrandGuide.Web\Views\Themes\Admin\Index.aspx:7
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Control.Render(HtmlTextWriter writer) +10
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
ASP.views_themes_admin_theme_master.__Render__control1(HtmlTextWriter __w, Control parameterContainer) in c:\S3_Depot\S3_Dev\GrandGuide\GrandGuide.Web\Views\Themes\Admin\Theme.Master:33
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +256
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Control.Render(HtmlTextWriter writer) +10
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer, ICollection children) +134
System.Web.UI.Control.RenderChildren(HtmlTextWriter writer) +19
System.Web.UI.Page.Render(HtmlTextWriter writer) +29
System.Web.Mvc.ViewPage.Render(HtmlTextWriter writer) +71
System.Web.UI.Control.RenderControlInternal(HtmlTextWriter writer, ControlAdapter adapter) +27
System.Web.UI.Control.RenderControl(HtmlTextWriter writer, ControlAdapter adapter) +99
System.Web.UI.Control.RenderControl(HtmlTextWriter writer) +25
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1266
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
更多信息会有帮助。过去,我使用过:
或者,如果您要访问上下文中的某些内容,例如会话变量:
More info would help. In the past, I've used:
or, if you're accessing something in the context such as a Session Variable: