本文整理汇总了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");
}
示例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();
}