Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Fahad Ayub 71 posts 238 karma points
    Jul 26, 2016 @ 15:37
    Fahad Ayub
    0

    no physical template file was found for template

    Hi, I have just created my own controller in existing Umbraco website. My controller is below :

    LoginController

    public class LoginController : Umbraco.Web.Mvc.RenderMvcController
    {
        // GET: Login
        public ActionResult Index()
        {
            return View();
        }
    }
    

    View (Views/Login/Index.cshtml)

    @{
    ViewBag.Title = "Index";}
    

    And I have also added a class to register custom routes:

    RouteHandler.cs

       using System.Web.Routing;
    using Umbraco.Core;
    using System.Web.Http;
    using System.Web.Mvc;
    namespace WebApplication1
    {
        public class RoutingHandler : ApplicationEventHandler
        {
            protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
            {
                RegisterCustomRoutes();
            }
    
            private static void RegisterCustomRoutes()
            {
    
    
                RouteTable.Routes.MapRoute(
        "SomeName",
        "Login/index",
        new
        {
            controller = "LoginController",
            action = "Index",
            id = UrlParameter.Optional
        });
    
            }
        }
    }
    

    But when I try to access page using http://Localhost/Login/Index

    I get error message

    no physical template file was found for template ..

    Any help.

    Thanks

  • Colin McFadden 4 posts 103 karma points
    Jul 26, 2016 @ 16:29
    Colin McFadden
    100

    Your controller value shouldn't include 'Controller'. So it should be...

    RouteTable.Routes.MapRoute(
        "SomeName",
        "Login/index",
        new
        {
            controller = "Login",
            action = "Index",
            id = UrlParameter.Optional
        });
    

    I've actually never used the ApplicationEventHandler method to hijack routes. I should try it.

    If you continue to have trouble, you could try creating a class in your project root that inherits the WebBootManager to hijack routing. This is the way I learned and it has worked for me. An example of that would be:

        namespace Example.Web
    {
        public class ExampleApplication : UmbracoApplication
        {
            protected override IBootManager GetBootManager()
            {
                return new ExampleBootManager(this);
            }
    
            protected override void OnApplicationStarting(object sender, EventArgs e)
            {
                BundleConfig.RegisterBundles(BundleTable.Bundles);
            }
        }
    
        class ExampleBootManager : WebBootManager
        {
            public ExampleBootManager(UmbracoApplication umbracoApplication) : base(umbracoApplication) { }
    
            public override IBootManager Complete(Action<ApplicationContext> afterComplete)
            {
                RouteTable.Routes.MapRoute(
                    "Home",
                    "home/index",
                    new { controller = "Home", action = "Index" }
                    );
                return base.Complete(afterComplete);
            }
        }
    }
    

    Hope this helps. I'm sure someone more knowledgeable than myself will chime in.

  • Fahad Ayub 71 posts 238 karma points
    Jul 27, 2016 @ 07:50
    Fahad Ayub
    0

    I removed 'Controller' and it worked. Thanks so much.

Please Sign in or register to post replies

Write your reply to:

Draft