本文整理汇总了C#中System.Web.Http.Routing.UrlHelper.Link方法的典型用法代码示例。如果您正苦于以下问题:C# UrlHelper.Link方法的具体用法?C# UrlHelper.Link怎么用?C# UrlHelper.Link使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Web.Http.Routing.UrlHelper
的用法示例。
在下文中一共展示了UrlHelper.Link方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Get
public HttpResponseMessage Get(int size, int page)
{
var helper = new UrlHelper(Request);
if (size > 100) size = 10;
int offset = page * size;
int next_page = page;
int prev_page = page;
//need to count max pages from total results and implement that
if (page < 1) { prev_page = 0; } else { prev_page--; }
next_page++;
var prev = helper.Link("QuestionApi", new { size = size, page = prev_page }).ToString();
var next = helper.Link("QuestionApi", new { size = size, page = next_page });
var response = Request
.CreateResponse(
HttpStatusCode.OK,
_questionRepository
.GetAllQuestions(size, offset)
.Select(question => ModelFactory.Create(question)))
;
response.Headers.Add("next-page", next);
response.Headers.Add("prev-page", prev);
return response;
}
示例2: Get
//[EnableCors("*", "*", "GET")]
public HttpResponseMessage Get(int page = 0, int pageSize = 10)
{
IQueryable<Course> query;
Learning.Data.LearningContext ctx = new Learning.Data.LearningContext();
Learning.Data.ILearningRepository repo = new Learning.Data.LearningRepository(ctx);
query = repo.GetAllCourses().OrderBy(c => c.CourseSubject.Id);
var totalCount = query.Count();
var totalPages = (int)Math.Ceiling((double)totalCount / pageSize);
var urlHelper = new UrlHelper(Request);
var prevLink = page > 0 ? urlHelper.Link("CoursesRoute", new { page = page - 1, pageSize = pageSize }) : "";
var nextLink = page < totalPages - 1 ? urlHelper.Link("CoursesRoute", new { page = page + 1, pageSize = pageSize }) : "";
var results = query
.Skip(pageSize * page)
.Take(pageSize)
.ToList();
var result = new
{
TotalCount = totalCount,
TotalPages = totalPages,
PrevPageLink = prevLink,
NextPageLink = nextLink,
Results = results
};
return Request.CreateResponse(HttpStatusCode.OK, result);
}
示例3: Get
public IEnumerable<StudentV2BaseModel> Get(int page = 0, int pageSize = 10)
{
IQueryable<Student> query;
query = TheRepository.GetAllStudentsWithEnrollments().OrderBy(c => c.LastName);
var totalCount = query.Count();
var totalPages = Math.Ceiling((double)totalCount / pageSize);
var urlHelper = new UrlHelper(Request);
var prevLink = page > 0 ? urlHelper.Link("Students", new { page = page - 1, pageSize = pageSize }) : "";
var nextLink = page < totalPages - 1 ? urlHelper.Link("Students", new { page = page + 1, pageSize = pageSize }) : "";
var paginationHeader = new
{
TotalCount = totalCount,
TotalPages = totalPages,
PrevPageLink = prevLink,
NextPageLink = nextLink
};
System.Web.HttpContext.Current.Response.Headers.Add("X-Pagination",
Newtonsoft.Json.JsonConvert.SerializeObject(paginationHeader));
var results = query
.Skip(pageSize * page)
.Take(pageSize)
.ToList()
.Select(s => TheModelFactory.CreateV2Summary(s));
return results;
}
示例4: Get
public object Get(int contactgroupid, int contactId = 0, int page = 0)
{
var userName = _identityService.CurrentUser;
var baseQuery = TheRepository.GetContactGroupContacts(_identityService.CurrentUser,contactgroupid)
.OrderByDescending(c => c.FirstName);
var totalCount = baseQuery.Count();
var totalPages = Math.Ceiling((double)totalCount / PAGE_SIZE);
var helper = new UrlHelper(Request);
var preUrl = page > 0 ? helper.Link("Contacts", new { page = page - 1 }) : "";
var newUrl = page < totalPages - 1 ? helper.Link("Contacts", new { page = page + 1 }) : "";
var results = baseQuery
.Skip(PAGE_SIZE * page)
.Take(PAGE_SIZE)
.ToList()
.Select(c => TheModelFactory.Create(c));
return new
{
TotalCount = totalCount,
TotalPages = totalPages,
PrevPageUrl = preUrl,
NextPageUrl = newUrl,
Results = results,
};
}
示例5: Get
public object Get(int page , int pageSize)
{
IQueryable<Course> query;
query = TheRepository.GetAllCourses().OrderBy(c => c.Name);
var totalCount = query.Count();
var totalPages = (int)Math.Ceiling((double)totalCount / pageSize);
var urlHelper = new UrlHelper(Request);
var prevLink = page > 0 ? urlHelper.Link("Courses", new { page = page - 1, pageSize = pageSize }) : "";
var nextLink = page < totalPages - 1 ? urlHelper.Link("Courses", new { page = page + 1, pageSize = pageSize }) : "";
var paginationHeader = new
{
TotalCount = totalCount,
TotalPages = totalPages,
PrevPageLink = prevLink,
NextPageLink = nextLink
};
System.Web.HttpContext.Current.Response.Headers.Add("X-Pagination",
Newtonsoft.Json.JsonConvert.SerializeObject(paginationHeader));
var results = query
.Skip(pageSize * page)
.Take(pageSize)
.ToList()
.Select(s => TheModelFactory.Create(s));
return results;
}
示例6: PageLinkBuilder
public PageLinkBuilder(UrlHelper urlHelper, string routeName, object routeValues, int pageNo, int pageSize, long totalRecordCount)
{
// Determine total number of pages
var pageCount = totalRecordCount > 0
? (int) Math.Ceiling(totalRecordCount/(double) pageSize)
: 0;
// Create them page links
FirstPage = new Uri(urlHelper.Link(routeName, new HttpRouteValueDictionary(routeValues)
{
{"pageNo", 1},
{"pageSize", pageSize}
}));
LastPage = new Uri(urlHelper.Link(routeName, new HttpRouteValueDictionary(routeValues)
{
{"pageNo", pageCount},
{"pageSize", pageSize}
}));
if (pageNo > 1)
{
PreviousPage = new Uri(urlHelper.Link(routeName, new HttpRouteValueDictionary(routeValues)
{
{"pageNo", pageNo - 1},
{"pageSize", pageSize}
}));
}
if (pageNo < pageCount)
{
NextPage = new Uri(urlHelper.Link(routeName, new HttpRouteValueDictionary(routeValues)
{
{"pageNo", pageNo + 1},
{"pageSize", pageSize}
}));
}
}
示例7: Get
public object Get(int userid,int notificationid = 0, int page = 0)
{
var userName = _identityService.CurrentUser;
var baseQuery = TheRepository.GetOrganizationNotifications(userName)
.OrderByDescending( c => c.DateAdded);
var totalCount = baseQuery.Count();
var totalPages = Math.Ceiling((double) totalCount/PAGE_SIZE);
var helper = new UrlHelper(Request);
var preUrl = page > 0 ? helper.Link("Notifications", new {page = page - 1}) : "";
var newUrl = page < totalPages - 1 ? helper.Link("Notifications", new { page = page + 1 }): "";
var results = baseQuery
.Skip(PAGE_SIZE * page)
.Take(PAGE_SIZE)
.ToList()
.Select(c => TheModelFactory.Create(c));
return new
{
TotalCount = totalCount,
TotalPages = totalPages,
PrevPageUrl = preUrl,
NextPageUrl = newUrl,
Results = results,
};
}
示例8: Get
public Object Get(int page = 0, int pageSize = 10)
{
IQueryable<Course> query;
query = TheRepository.GetAllCourses().OrderBy(c => c.CourseSubject.Id);
var totalCount = query.Count();
var totalPages = (int)Math.Ceiling((double)totalCount / pageSize);
var urlHelper = new UrlHelper(Request);
var prevLink = page > 0 ? urlHelper.Link("Courses", new { page = page - 1, pageSize = pageSize }) : "";
var nextLink = page < totalPages - 1 ? urlHelper.Link("Courses", new { page = page + 1, pageSize = pageSize }) : "";
var results = query
.Skip(pageSize * page)
.Take(pageSize)
.ToList()
.Select(s => TheModelFactory.Create(s));
return new
{
TotalCount = totalCount,
TotalPages = totalPages,
PrevPageLink = prevLink,
NextPageLink = nextLink,
Results = results
};
}
示例9: GetAllPaging
public IQueryable<EventDTO> GetAllPaging(int page, int pageSize)
{
var list = _service.GetAllPaging(page, pageSize);
if (list != null)
{
var totalCount = _service.GetTotalResults();
var totalPages = (int)Math.Ceiling((double)totalCount / pageSize);
var urlHelper = new UrlHelper(Request);
var prevLink = page > 1 ? urlHelper.Link("GetAllPagingRoute", new { page = page - 1, pageSize = pageSize }) : "";
var nextLink = page < totalPages ? urlHelper.Link("GetAllPagingRoute", new { page = page + 1, pageSize = pageSize }) : "";
var firstLink = page != 1 ? urlHelper.Link("GetAllPagingRoute", new { page = 1, pageSize = pageSize }) : "";
var lastLink = page != totalPages ? urlHelper.Link("GetAllPagingRoute", new { page = totalPages, pageSize = pageSize }) : "";
var paginationHeader = new
{
TotalCount = totalCount,
TotalPages = totalPages,
PrevPageLink = prevLink,
NextPageLink = nextLink,
FirstPageLink = firstLink,
LastPageLink = lastLink
};
System.Web.HttpContext.Current.Response.Headers.Add("X-Pagination",
Newtonsoft.Json.JsonConvert.SerializeObject(paginationHeader));
}
return Queryable.AsQueryable(list);
}
示例10: Get
public IHttpActionResult Get(int expenseGroupId, string fields = null, string sort = "Date", int page = 1, int pageSize = maxPageSize)
{
try
{
IQueryable<Expense> expenses = _repository.GetExpenses(expenseGroupId);
if (expenses == null)
{
return NotFound();
}
List<string> listOfFields = new List<string>();
if (fields != null)
{
listOfFields = fields.Split(',').ToList();
}
if (pageSize > maxPageSize)
{
pageSize = maxPageSize;
}
int totalCount = expenses.Count();
int totalPages = (int)Math.Ceiling((double)totalCount / pageSize);
UrlHelper urlHelper = new UrlHelper(Request);
string prevLink = page > 1 ? urlHelper.Link("ExpensesForGroup",
new
{
page = page - 1,
pageSize = pageSize,
expenseGroupId = expenseGroupId,
sort = sort
}) : "";
var nextLink = page < totalPages ? urlHelper.Link("ExpensesForGroup",
new
{
page = page + 1,
pageSize = pageSize,
expenseGroupId = expenseGroupId,
sort = sort
}) : "";
var paginationHeader = new
{
currentPage = page,
pageSize = pageSize,
totalCount = totalCount,
totalPages = totalPages,
previousPageLink = prevLink,
nextPageLink = nextLink
};
HttpContext.Current.Response.Headers.Add("X-Pagination", Newtonsoft.Json.JsonConvert.SerializeObject(paginationHeader));
var expensesResult = expenses
.ApplySort(sort)
.Skip(pageSize * (page - 1))
.Take(pageSize)
.ToList()
.Select(exp => _expenseFactory.CreateDataShapedObject(exp, listOfFields));
return Ok(expensesResult);
}
catch (Exception exception)
{
return InternalServerError();
}
}
示例11: Get
public IEnumerable<Product> Get(string sort = "ProductId", int page = 1, int pageSize = maxPageSize)
{
try
{
IProductDetailDao repository = new ProductDetailDao();
var products= repository.GetAllProducts(sort);
// ensure the page size isn't larger than the maximum.
if (pageSize > maxPageSize)
{
pageSize = maxPageSize;
}
// calculate data for metadata
var totalCount = products.Count();
var totalPages = (int)Math.Ceiling((double)totalCount / pageSize);
var urlHelper = new UrlHelper(Request);
var prevLink = page > 1 ? urlHelper.Link("ProductListing",
new
{
page = page - 1,
pageSize = pageSize,
sort = sort
}) : "";
var nextLink = page < totalPages ? urlHelper.Link("ProductListing",
new
{
page = page + 1,
pageSize = pageSize,
sort = sort
}) : "";
var paginationHeader = new
{
currentPage = page,
pageSize = pageSize,
totalCount = totalCount,
totalPages = totalPages,
previousPageLink = prevLink,
nextPageLink = nextLink
};
HttpContext.Current.Response.Headers.Add("X-Pagination",
Newtonsoft.Json.JsonConvert.SerializeObject(paginationHeader));
// return result
return (products
.Skip(pageSize * (page - 1))
.Take(pageSize)
.ToList());
}
catch (Exception)
{
throw;
}
}
示例12: Get
public object Get(bool includeReviews = true, int page = 1)
{
IQueryable<Restaurant> query;
if (includeReviews)
{
query = Repository.GetAllRestaurantsWithReviewes();
}
else
{
query = Repository.GetAllRestaurants();
}
var baseQuery = query.OrderBy(r => r.Name);
var totalCount = baseQuery.Count();
var totalPages = (int)Math.Ceiling((double) totalCount/PAGE_SIZE);
var helper = new UrlHelper(Request);
var links = new List<LinkModel>();
if (page > 1)
links.Add(ModelFactory.CreateLink(helper.Link("restaurants", new { page = page - 1 }), "prevPage"));
if (page < totalPages)
links.Add(ModelFactory.CreateLink(helper.Link("restaurants", new { page = page + 1 }), "nextPage"));
/*
var prevUrl = page > 1 ? helper.Link("restaurants", new { includeReviews = includeReviews, page = page - 1 }) : "";
var nextUrl = page < totalPages ? helper.Link("restaurants", new { includeReviews = includeReviews, page = page + 1 }) : "";
*/
var results = baseQuery
.Skip(PAGE_SIZE*(page - 1))
.Take(PAGE_SIZE)
.ToList()
.Select(r => ModelFactory.Create(r));
return new
{
TotalCount = totalCount,
TotalPages = totalPages,
Links = links,
Results = results,
};
/*
return new
{
TotalCount = totalCount,
TotalPages = totalPages,
PrevPageUrl = prevUrl.ToLower(),
NextPageUrl = nextUrl.ToLower(),
Results = results,
};
*/
}
示例13: CreatePagination
public static Pagination CreatePagination(UrlHelper urlHelper, int currentOffset, int limit, int totalResults)
{
var pagination = new Rozo.Web.Helpers.Pagination();
pagination.Current = currentOffset;
pagination.Pages = totalResults % limit == 0 ? totalResults / limit : totalResults / limit + 1;
pagination.Next = currentOffset + limit > totalResults ? null : urlHelper.Link("DefaultApi", new { offset = currentOffset + limit, limit = limit, totalResults = totalResults });
pagination.Previous = currentOffset == 0 ? null : urlHelper.Link("DefaultApi", new { offset = currentOffset - limit < 0 ? 0 : currentOffset - limit, limit = limit, totalResults = totalResults });
return pagination;
}
示例14: GetPostsResourceCollectionInfo
private ResourceCollectionInfo GetPostsResourceCollectionInfo(UrlHelper url) {
ResourceCollectionInfo posts = new ResourceCollectionInfo("Blog",
new Uri(url.Link("DefaultApi", new { controller = "posts" })));
posts.Accepts.Add("application/atom+xml;type=entry");
// For WLW to work we need to include format in the categories URI.
// Hoping to provide a better solution than this.
var categoriesUri = new Uri(url.Link("DefaultApi", new { controller = "tags", format = "atomcat" }));
ReferencedCategoriesDocument categories = new ReferencedCategoriesDocument(categoriesUri);
posts.Categories.Add(categories);
return posts;
}
示例15: Enrich
private void Enrich(TodoRepresentation todo, UrlHelper url)
{
var selfUrl = url.Link("DefaultApi", new { controller = "todos", todo.id });
todo.AddLink(new SelfLink(selfUrl));
todo.AddLink(new EditLink(selfUrl));
todo.AddLink(new DeleteLink(selfUrl));
}