Beispiel #1
0
        public ActionResult Routing(RoutingViewData iViewData)
        {
            IRoutable model;
            var       viewId = RoutableExtension.Route(ref iViewData, out model);

            if (viewId != null)
            {
                ViewData["Routing"] = iViewData;
                return(Demo(viewId.Replace("/Demo/", ""), model));
            }
            return(new EmptyResult());
        }
Beispiel #2
0
        public IViewComponentResult Invoke(RoutingViewData iViewData)
        {
            IRoutable model;
            var       viewId = RoutableExtension.Route(ref iViewData, out model);

            if (viewId != null)
            {
                ViewData["Routing"] = iViewData;
                var id = viewId.Replace("/Demo/", "");
                if (id.EndsWith("_cshtml"))
                {
                    return(View("/Views/" + id.Replace("_cshtml", ".cshtml"), model?.GetType() != typeof(object) ? model : null));
                }

                var htmlFilePath = Path.Combine(_hostingEnvironment.ContentRootPath, "Views\\" + (id.EndsWith(".html") ? id : id + ".html"));
                return(new HtmlResult(htmlFilePath));
            }
            return(null);
        }
Beispiel #3
0
        public void Routing_RouteBookDetails()
        {
            var viewData = new RoutingViewData("/index/books/book/the-martian", "/Index_cshtml", typeof(TestNavBarVM));

            object model;
            string viewId = String.Empty;

            viewId = RoutableExtension.Route(ref viewData, out model);
            Assert.IsNotNull(viewId);
            Assert.AreEqual("/Index_cshtml", viewId);
            Assert.IsNotNull(model is TestNavBarVM);

            var activatedEventArgs = (model as TestNavBarVM).TestActivatedEventArgs;

            Assert.IsNotNull(activatedEventArgs);
            Assert.AreEqual("books", activatedEventArgs.Active);

            viewId = RoutableExtension.Route(ref viewData, out model);
            Assert.IsNotNull(viewId);
            Assert.AreEqual("/BookStore_cshtml", viewId);
            Assert.IsNotNull(model is TestBookStoreVM);

            activatedEventArgs = (model as TestBookStoreVM).TestActivatedEventArgs;
            Assert.IsNotNull(activatedEventArgs);
            Assert.AreEqual("book/the-martian", activatedEventArgs.Active);

            viewId = RoutableExtension.Route(ref viewData, out model);
            Assert.IsNotNull(viewId);
            Assert.AreEqual("/BookDetails_cshtml", viewId);
            Assert.IsNotNull(model is TestBookDetailsVM);

            var routedEventArgs = (model as TestBookDetailsVM).TestRoutedEventArgs;

            Assert.IsNotNull(routedEventArgs);
            Assert.AreEqual("book/the-martian", routedEventArgs.From);
        }