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?

Mark Rogers
  • 96,497
  • 18
  • 85
  • 138

2 Answers2

3

In your FubuRegistry, in the "Views" section, add:

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

For example, the whole views section may look like:

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

Note that you can both ASPX and ASCX for headless views. If you only want ASCX files, then you can use WebFormViewFacility.IsWebFormControl instead.

chadmyers
  • 3,800
  • 21
  • 29
  • Sorry to bother you again, thanks for all the great answers. For some reason when I make the changes you suggest the url can't find the view anymore. I added some more detail to the question, and a few relevant files – Mark Rogers Mar 05 '11 at 17:05
  • I believe PartialOnly() means that you cannot view it in a browser -- only use it in partials. – ulu Jun 26 '11 at 11:42
2

Works for me:

Views.RegisterActionLessViews(type => type.Name == "StaticView", 
       chain => chain.Route = new RouteDefinition("StaticView"));
ulu
  • 5,872
  • 4
  • 42
  • 51