【发布时间】:2017-03-27 06:52:48
【问题描述】:
我想创建一个应用程序,如果有 Ajax 调用它返回部分视图,如果是页面刷新它返回布局和渲染脚本。但问题是部分视图不会呈现部分,因为我在 APP_Code 中创建了一个 MVC 助手:
@helper AddSection(Func<object, object> content)
{
if (IsAjaxRequest)
{
@content(null);
}
else
{
@section scripts {
@content(null);
}
}
}
当我在我看来调用它时,我收到以下错误:
CS0103: The name 'DefineSection' does not exist in the current context
Line 71: #line hidden
Line 72: DefineSection("scripts", () => {
Line 73:
我尝试了很多东西但是这个错误仍然存在,我也搜索了很多但找不到解决方案。
【问题讨论】:
-
为了清楚起见,您想调用两次相同的操作。一次使用标准 get 请求,一次使用 xhr ajax 请求?
-
是的,正是……
标签: asp.net-mvc asp.net-mvc-4 razor html-helper razorgenerator