本文整理汇总了C#中System.Web.Mvc.UrlHelper.BuildUrl方法的典型用法代码示例。如果您正苦于以下问题:C# UrlHelper.BuildUrl方法的具体用法?C# UrlHelper.BuildUrl怎么用?C# UrlHelper.BuildUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Mvc.UrlHelper
的用法示例。
在下文中一共展示了UrlHelper.BuildUrl方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Pager
/// <summary>
/// Render HTML pager element for specified search query.
/// </summary>
/// <param name="html">The html helper object.</param>
/// <param name="query">The search query object.</param>
/// <param name="htmlAttributes">The html attributes object for the output html element.</param>
/// <returns></returns>
public static HelperResult Pager(this HtmlHelper html, SearchQuery query, object htmlAttributes = null)
{
return new HelperResult(writer =>
{
var Url = new UrlHelper(html.ViewContext.RequestContext);
var website = html.ViewContext.RouteData.Values["website"].ToString();
var locale = html.ViewContext.RouteData.Values["locale"].ToString();
var _url = App.Get().Context.AppUrl + website + "/" + locale + "search/" + query.Source;
var maxPageCount = 10;
var curIndex = query.Index;
var startIndex = 1;
var endIndex = maxPageCount * startIndex;
var curPage = (int)Math.Ceiling((decimal)((decimal)curIndex / (decimal)maxPageCount));
if (curPage > 1)
startIndex = (curPage * maxPageCount) - maxPageCount + 1;
endIndex = startIndex + maxPageCount;
if (endIndex > query.TotalPages)
endIndex = query.TotalPages;
var _params = new List<string>();
var queryString = html.ViewContext.RequestContext.HttpContext.Request.QueryString;
if (queryString != null)
{
foreach (var key in queryString.AllKeys)
{
if (key.Equals("index", StringComparison.OrdinalIgnoreCase) || key.Equals("size", StringComparison.OrdinalIgnoreCase))
continue;
_params.Add(string.Format("{0}={1}", key, queryString[key]));
}
}
var isLast = curPage * maxPageCount >= query.TotalPages;
var isFirst = startIndex == 1;
var builder = new UriBuilder();
//if (startIndex == endIndex && startIndex == 1)
// return;
if (isLast)
endIndex++;
var pageElement = new XElement("div", new XAttribute("class", "d-pager"));
pageElement.AddHtmlAttributes(htmlAttributes);
if (!isFirst)
{
pageElement.Add(
new XElement("a",
new XAttribute("href", Url.BuildUrl(_url, _params)),
new XAttribute("title", "First"),
new XAttribute("class", "d-ui-widget d-button"),
new XElement("span", new XAttribute("class", "d-icon d-icon-first"))),
new XElement("a",
new XAttribute("href", _url + "?index=" + (curIndex - 1).ToString() + "&size=" + query.Size + (_params.Count > 0 ? ("&" + string.Join("&", _params.ToArray())) : "")),
new XAttribute("title", "Prev"),
new XElement("span", new XAttribute("class", "d-icon d-icon-prev")))
);
}
for (int i = startIndex; i < endIndex; i++)
{
var pagerItem = new XElement("a", i != curIndex ? i : curIndex);
if (i == curIndex)
pagerItem.Add(new XAttribute("class", "d-ui-widget d-button d-state-active"));
else
pagerItem.Add(new XAttribute("class", "d-ui-widget d-button"));
if (i != curIndex)
pagerItem.Add(new XAttribute("href", _url + "?index=" + i.ToString() + "&size=" + query.Size + (_params.Count > 0 ? ("&" + string.Join("&", _params.ToArray())) : "")));
pageElement.Add(pagerItem);
}
if (!isLast)
{
pageElement.Add(
new XElement("a",
new XAttribute("href", _url + "?index=" + (curIndex + 1).ToString() + "&size=" + query.Size + (_params.Count > 0 ? ("&" + string.Join("&", _params.ToArray())) : "")),
new XAttribute("title", "Next"),
new XAttribute("class", "d-ui-widget d-button"),
new XElement("span", new XAttribute("class", "d-icon d-icon-next"))),
new XElement("a",
new XAttribute("href", _url + "?index=" + (query.TotalPages).ToString() + "&size=" + query.Size + (_params.Count > 0 ? ("&" + string.Join("&", _params.ToArray())) : "")),
new XAttribute("title", "Last"),
new XAttribute("class", "d-ui-widget d-button"),
new XElement("span", new XAttribute("class", "d-icon d-icon-last")))
);
}
//.........这里部分代码省略.........