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


C# UrlHelper.Link方法代码示例

本文整理汇总了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;
        }
开发者ID:harksha,项目名称:rawdata0,代码行数:25,代码来源:QuestionsController.cs

示例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);

        }
开发者ID:GodinSession,项目名称:eLearning.WebAPI,代码行数:34,代码来源:CoursesController.cs

示例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;
        }
开发者ID:jackyped,项目名称:WebApi.eLearning,代码行数:32,代码来源:StudentsV2Controller.cs

示例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,
            };
        }
开发者ID:shturner20,项目名称:EContact,代码行数:29,代码来源:ContactsController.cs

示例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;
        }
开发者ID:likesea,项目名称:WebApi,代码行数:32,代码来源:CoursesController.cs

示例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}
                }));
            }
        }
开发者ID:astek98,项目名称:WebApiPaging,代码行数:35,代码来源:PageLinkBuilder.cs

示例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,
            };
        }
开发者ID:shturner20,项目名称:EContact,代码行数:29,代码来源:NotificationsController.cs

示例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
            };

        }
开发者ID:jhalbrecht,项目名称:eLearning.WebAPI,代码行数:28,代码来源:CoursesController.cs

示例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);
        }
开发者ID:hiepbp11395,项目名称:Event,代码行数:31,代码来源:EventsController.cs

示例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();
     }
 }
开发者ID:towhidulbashar,项目名称:ExpenseTracker,代码行数:60,代码来源:ExpensesController.cs

示例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;
            }
        }
开发者ID:abkhan5,项目名称:AppVerse,代码行数:59,代码来源:ProductsController.cs

示例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,
                };
            */
        }
开发者ID:vadpetrov,项目名称:Pluralsight,代码行数:58,代码来源:RestaurantsController.cs

示例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;
        }
开发者ID:gljivar,项目名称:Rozo.Net,代码行数:10,代码来源:PaginationHelper.cs

示例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;
        }
开发者ID:mahf,项目名称:ASPNETWebAPISamples,代码行数:15,代码来源:AtomPubServiceDocumentDispatcher.cs

示例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));
 }
开发者ID:chrismcbride76,项目名称:TodoApp-WebApi,代码行数:7,代码来源:TodoResponseEnricher.cs


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