【发布时间】:2011-07-09 07:40:50
【问题描述】:
我有一个Index 对一个没有做任何事情的控制器的操作。
public EmptyModel Index()
{
return null;
}
Index 视图仅显示一些 html,使用 jQuery 驱动的 ajax 和 MasterPage 在此特定页面上完成所有繁重的工作。当我从它的控制器中删除这个动作函数时,aspx 视图将不再显示。
更多信息和更新:
在进行 Chad 的回答中提到的更改后,用于返回索引视图的 url 现在返回 404。这个问题可能存在,因为大多数视图的文件夹结构都是在早期的 Fubu 框架样式中完成的(@987654324 @ 并且没有代码隐藏),而不是使用更直观和更新的默认文件夹约定。但有可能我的分析失败了。
这是我的 FubuRegistry:
public WebAppFubuRegistry()
{
IncludeDiagnostics(true);
Services(x => x.SetServiceIfNone<IWebAppSecurityContext, WebAppSecurityContext>());
Applies.ToThisAssembly()
.ToAssemblyContainingType<HomeController>();
Actions
.IncludeClassesSuffixedWithController();
Routes
.UrlPolicy<WebAppUrlPolicy>()
.IgnoreControllerNamespaceEntirely()
.ConstrainToHttpMethod(action => action.Method.Name.StartsWith("Perform"), "POST");
Views
.TryToAttach(x=> x.by<ViewAndActionInDifferentFolders>())
.TryToAttachWithDefaultConventions()
.RegisterActionLessViews(WebFormViewFacility.IsWebFormView,
chain => chain.PartialOnly());
/*Behavior Code */
}
WebAppUrlPolicy:
public class WebAppUrlPolicy : IUrlPolicy
{
public bool Matches(ActionCall call, IConfigurationObserver log)
{
return true;
}
public IRouteDefinition Build(ActionCall call)
{
if(call.IsForHomeController())
return new RouteDefinition("home");
if(call.IsAnIndexCall())
return new RouteDefinition(call.ControllerPrefix());
var otherRoute = new RouteDefinition(call.ToControllerActionRoute());
return otherRoute;
}
}
ViewAndActionInDifferentFolders:
public class ViewAndActionInDifferentFolders : IViewsForActionFilter
{
public IEnumerable<IViewToken> Apply(ActionCall call, ViewBag views)
{
if (call.IsForHomeController())
{
var viewTokens = views.ViewsFor(call.OutputType()).Where(x => x.Name == "HomeIndexView");
return new[] { new WebAppViewToken(call, viewTokens, "home") };
}
if (call.IsJsonCall())
{
return new List<IViewToken>();
}
return CreateSingleTokenList(call, views);
}
private static IEnumerable<WebAppViewToken> CreateSingleTokenList(ActionCall call, ViewBag views)
{
return new[] { new WebAppViewToken(call, views.ViewsFor(call.OutputType())) };
}
}
如何重新配置 Fubu 以便我可以在没有操作的情况下使用视图?
需要进行哪些更改才能删除上面的操作功能,并且仍然保持相同的功能?
【问题讨论】:
标签: fubumvc