当前位置: 首页>>代码示例>>C#>>正文


C# UrlHelper.Href方法代码示例

本文整理汇总了C#中System.Web.Mvc.UrlHelper.Href方法的典型用法代码示例。如果您正苦于以下问题:C# UrlHelper.Href方法的具体用法?C# UrlHelper.Href怎么用?C# UrlHelper.Href使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Web.Mvc.UrlHelper的用法示例。


在下文中一共展示了UrlHelper.Href方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Search

        public ActionResult Search(string s, int? page, int? pageSize)
        {
            if (s.IsNullOrTrimmedEmpty())
            {
                return View("NoProductFound");
            }
            var pageId = GetPageId(page);

            s = s.Trim();
            s = Noises.Clean("fr", s);

            int count = 0;
            pageSize = pageSize.GetValueOrDefault(ERPStoreApplication.WebSiteSettings.Catalog.PageSize);
            var parameters = CatalogService.RemoveNotFilteredParameters(Request.Url.Query.ToHtmlDecodedNameValueDictionary());
            var category = CatalogService.GetCategoryByCode(Request["category"]);
            var brand = CatalogService.GetBrandByName(Request["brand"]);

            var filter = CatalogService.CreateProductListFilter(HttpContext);
            filter.ExtendedParameters = parameters;
            filter.Search = s;
            if (category != null)
            {
                filter.ProductCategoryId = category.Id;
            }
            if (brand != null)
            {
                filter.BrandId = brand.Id;
            }
            var productList = CatalogService.GetProductListBySearch(filter, pageId, pageSize.Value, out count);

            if (pageId == 0)
            {
                EventPublisherService.Publish(new Models.Events.ProductSearchEvent(User.GetUserPrincipal(), s, count, CatalogService.Name));
                ViewData["search"] = filter.Search;
                ViewData["resultCount"] = count;
            }

            if (productList == null || productList.Count == 0)
            {
                return View("NoProductFound");
            }

            // Afficher directement la fiche produit
            if (productList.Count == 1)
            {
                var p = productList.First();
                var urlHelper = new UrlHelper(this.ControllerContext.RequestContext);
                var url = urlHelper.Href(p);
                return Redirect(url);
            }

            // Recherche des tarifs client si celui-ci est connecté
            CatalogService.ApplyBestPrice(productList, User.GetUserPrincipal().CurrentUser);

            var result = new Models.ProductList(productList);
            result.Query = s;
            result.ItemCount = count;
            result.PageIndex = pageId + 1;
            result.PageSize = pageSize.Value;
            result.ExtendedParameters = parameters;
            result.Category = category;
            result.Brand = brand;
            result.ListType = ERPStore.Models.ProductListType.Search;

            ViewData.Model = result;
            return View("ProductSearchResult");
        }
开发者ID:hhariri,项目名称:ReSharper8Demo,代码行数:67,代码来源:CatalogController.cs

示例2: Category

        public ActionResult Category(string link, int? page, int? pageSize)
        {
            if (link != null)
            {
                link = link.Trim().TrimEnd('/');
            }
            else
            {
                // return RedirectToAction("CategoryList");
                return RedirectToERPStoreRoute(ERPStoreRoutes.PRODUCT_CATEGORIES);
            }
            var category = CatalogService.GetCategoryByLink(link);
            if (category == null)
            {
                // Recherche dans la liste de compensation
                string fileName = Server.MapPath(@"/app_data/categories-compensation.txt");
                var categoryCompensationListFileInfo = new System.IO.FileInfo(fileName);
                if (!categoryCompensationListFileInfo.Exists)
                {
                    Logger.Notification("Missing category : {0} on {1}", link, fileName);
                    return new RedirectResult("/");
                }
                using (var content = categoryCompensationListFileInfo.OpenText())
                {
                    while(true)
                    {
                        var line = content.ReadLine();
                        if (line.IsNullOrTrimmedEmpty())
                        {
                            break;
                        }
                        string[] compensation = line.Split(':');
                        var badlink = compensation[0];
                        if (badlink.Equals(link, StringComparison.InvariantCultureIgnoreCase))
                        {
                            category = CatalogService.GetCategoryByLink(compensation[1]);
                            if (category != null)
                            {
                                break;
                            }
                        }
                    }
                }
                if (category == null)
                {
                    var adminUrl = string.Format("http://{0}/admin/ProductCategoryUrlMovedPermanently?badUrl={1}", ERPStoreApplication.WebSiteSettings.CurrentUrl, link);
                    Logger.Notification("Missing category : {0}\r\n {1}", link, adminUrl);
                    return new RedirectResult("/");
                }
                else
                {
                    var urlHelper = new UrlHelper(this.ControllerContext.RequestContext);
                    var redirect = urlHelper.Href(category);
                    MovedPermanently(redirect);
                }
            }
            if (!page.HasValue || page < 0)
            {
                page = 0;
            }
            else
            {
                page = page.Value - 1;
            }
            if (page < 0)
            {
                page = 0;
            }
            int count = 0;
            pageSize = pageSize.GetValueOrDefault(ERPStoreApplication.WebSiteSettings.Catalog.PageSize);
            var parameters = CatalogService.RemoveNotFilteredParameters(Request.Url.Query.ToHtmlDecodedNameValueDictionary());
            var brand = CatalogService.GetBrandByName(Request["brand"]);

            var productSearch = CatalogService.CreateProductListFilter(this.HttpContext);
            if (brand != null)
            {
                productSearch.BrandId = brand.Id;
            }
            productSearch.ProductCategoryId = category.Id;
            productSearch.ExtendedParameters = parameters;

            var productList = CatalogService.GetProductListBySearch(productSearch, page.Value, pageSize.Value, out count);

            // Recherche des tarifs client si celui-ci est connecté
            CatalogService.ApplyBestPrice(productList, User.GetUserPrincipal().CurrentUser);

            var pageIndex = page.Value + 1;

            var result = new Models.ProductList(productList);
            result.Category = category;
            result.ItemCount = count;
            result.PageIndex = pageIndex;
            result.PageSize = pageSize.Value;
            result.ExtendedParameters = parameters;
            result.ListType = ERPStore.Models.ProductListType.Category;
            result.Brand = brand;
            ViewData.Model = result;

            return View();
        }
开发者ID:hhariri,项目名称:ReSharper8Demo,代码行数:100,代码来源:CatalogController.cs


注:本文中的System.Web.Mvc.UrlHelper.Href方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。