2

I have an Index action on a controller that's not doing anything.

public EmptyModel Index()
{
     return null;
}

The Index view simply displays some html, with jQuery-driven ajax and the MasterPage doing all the heavy lifting on this particular page. When I remove this action function from it's controller, the aspx view will no longer display.


More Information and Update:

After making the changes mentioned in Chad's answer the url that used to return the index view now instead returns a 404. This issue may exist because most of the views' folder structure is done in the early Fubu Framework style (with View_Page_Type_Declarations.cs and no code-behinds), rather than using the more intuitive and more recent default folder conventions. But it's possible my analysis is off.

Here's my 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())) };
        }
    }

How do I reconfigure Fubu so that I can use a view without the action?

What changes need to be made to remove the action function above, and still maintain the same functionality?

4

2 回答 2

3

在 FubuRegistry 的“视图”部分中,添加:

.RegisterActionLessViews(WebFormViewFacility.IsWebFormView, chain => chain.PartialOnly());

例如,整个视图部分可能如下所示:

        Views
            .TryToAttachWithDefaultConventions()
            .RegisterActionLessViews(
                                        WebFormViewFacility.IsWebFormView, 
                                        chain => chain.PartialOnly());

请注意,您可以将 ASPX 和 ASCX 都用于无头视图。如果您只想要 ASCX 文件,那么您可以WebFormViewFacility.IsWebFormControl改用。

于 2011-03-05T14:38:42.710 回答
2

为我工作:

Views.RegisterActionLessViews(type => type.Name == "StaticView", 
       chain => chain.Route = new RouteDefinition("StaticView"));
于 2011-06-14T18:19:59.603 回答