Exemple #1
0
        public ActionResult Index(NorthwindPage currentPage)
        {
            var model = new NorthwindPageViewModel(currentPage);

            // connect to the Northwind database through the domain model
            // to fetch a list of all categories and pass it to the Northwind page
            // instance to show a list of category names and links generated
            // by the partial router.

            var db = new Northwind();

            // we do not need to track changes or
            // automatically load related entities
            db.Configuration.ProxyCreationEnabled = false;
            db.Configuration.LazyLoadingEnabled   = false;

            foreach (Category category in db.Categories)
            {
                model.CategoryLinks.Add(category.CategoryName,
                                        UrlResolver.Current.GetVirtualPathForNonContent(
                                            partialRoutedObject: category,
                                            language: null,
                                            virtualPathArguments: null)
                                        .GetUrl());
            }
            return(View(model));
        }
        public ActionResult Index()
        {
            // Note: the GetRoutedData extension method uses the partial router to
            // convert a URL segment into a Category instance.
            var category = Request.RequestContext.GetRoutedData <Category>();

            var northwindPages = ServiceLocator.Current.GetInstance <IContentLoader>()
                                 .GetChildren <NorthwindPage>(ContentReference.StartPage);

            NorthwindPage currentPage = null;

            if (northwindPages.Any())
            {
                currentPage = northwindPages.First();
            }

            var model = new NorthwindPageViewModel(currentPage);

            model.Category = category;

            return(View(model));
        }