本文整理汇总了C#中System.Web.Http.Routing.UrlHelper类的典型用法代码示例。如果您正苦于以下问题:C# UrlHelper类的具体用法?C# UrlHelper怎么用?C# UrlHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UrlHelper类属于System.Web.Http.Routing命名空间,在下文中一共展示了UrlHelper类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: 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
示例2: 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
示例3: 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
示例4: 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
示例5: SetUp
public void SetUp()
{
var config = new HttpConfiguration();
var request = new HttpRequestMessage(HttpMethod.Post, "http://dragonapi.devjakobsen.dk/api/player");
var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}");
var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "player" } });
playerController = new PlayerController();
UrlHelper urlHelper = new UrlHelper(request);
playerController.ControllerContext = new HttpControllerContext(config, routeData, request);
playerController.Request = request;
playerController.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
playerController.Request.Properties[HttpPropertyKeys.HttpRouteDataKey] = routeData;
playerController.Url = urlHelper;
var response = teamController.Get(1);
var contentResult = response as OkNegotiatedContentResult<DTOTeam>;
DTOTeam DtoTeam = contentResult.Content;
Team teamFromDb = new Team();
teamFromDb.Name = DtoTeam.Name;
teamFromDb.Id = DtoTeam.Id;
List<Team> teams = new List<Team>() { teamFromDb };
player = new Player() { Name = "Integration Test Player", Teams = teams };
}
开发者ID:theklausster,项目名称:DragonsLair,代码行数:30,代码来源:PlayerIntegrationTest.cs
示例6: 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
示例7: GenerateLinkDirectly_ReturnsNull_IfHelperRequestHasNoConfiguration
public void GenerateLinkDirectly_ReturnsNull_IfHelperRequestHasNoConfiguration()
{
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, "http://localhost/vpath/prefix/Customers");
UrlHelper urlHelper = new UrlHelper(request);
Assert.Null(urlHelper.GenerateLinkDirectly("OData", "odataPath"));
}
开发者ID:brianly,项目名称:aspnetwebstack,代码行数:7,代码来源:ODataUrlHelperExtensionsTest.cs
示例8: 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
示例9: 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
示例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 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
示例12: 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
示例13: 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
示例14: ToResponse
public static OptionResponse ToResponse(this Option<Team> option, UrlHelper urlHelper = null)
{
var response = new OptionResponse
{
CutOff = option.CutOff,
GameId = option.GameId,
GroupId = option.GroupId,
Id = option.Id,
IsPastCutOff = option.IsPastCutOff,
IsWinner = option.IsWinner,
Outcome = option.Outcome,
Team = option.Team,
Type = option.Type,
Value = option.Value
};
if (option.Pick != null && urlHelper != null)
{
response.Pick = option.Pick.ToResponse(urlHelper, response.IsPastCutOff);
}
if (urlHelper != null && !response.IsPastCutOff)
{
response.Actions.Add("pick", urlHelper.Route("DefaultNfl", new { controller = "picks", id = option.Id }));
}
return response;
}
开发者ID:hecubu5,项目名称:sportpicks,代码行数:28,代码来源:ModelToResponseExtensions.cs
示例15: ODataFeedSerializerTests
public ODataFeedSerializerTests()
{
_model = SerializationTestsHelpers.SimpleCustomerOrderModel();
_customerSet = _model.FindDeclaredEntityContainer("Default.Container").FindEntitySet("Customers");
_customers = new[] {
new Customer()
{
FirstName = "Foo",
LastName = "Bar",
ID = 10,
},
new Customer()
{
FirstName = "Foo",
LastName = "Bar",
ID = 42,
}
};
_customersType = new EdmCollectionTypeReference(
new EdmCollectionType(
new EdmEntityTypeReference(
_customerSet.ElementType,
isNullable: false)),
isNullable: false);
_urlHelper = new Mock<UrlHelper>(new HttpRequestMessage()).Object;
_writeContext = new ODataSerializerWriteContext(new ODataResponseContext()) { EntitySet = _customerSet, UrlHelper = _urlHelper };
}
开发者ID:chrisortman,项目名称:aspnetwebstack,代码行数:29,代码来源:ODataFeedSerializerTests.cs
示例16: SetUp
public void SetUp()
{
var config = new HttpConfiguration();
var request = new HttpRequestMessage(HttpMethod.Post, "http://dragonapi.devjakobsen.dk/api/game");
var route = config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}");
var routeData = new HttpRouteData(route, new HttpRouteValueDictionary { { "controller", "game" } });
gameController = new GameController();
UrlHelper urlHelper = new UrlHelper(request);
gameController.ControllerContext = new HttpControllerContext(config, routeData, request);
gameController.Request = request;
gameController.Request.Properties[HttpPropertyKeys.HttpConfigurationKey] = config;
gameController.Request.Properties[HttpPropertyKeys.HttpRouteDataKey] = routeData;
gameController.Url = urlHelper;
genreController = new GenreController();
var response = genreController.Get(1);
var contentResult = response as OkNegotiatedContentResult<DTOGenre>;
DTOGenre DtoGenre = contentResult.Content;
genrefromDb = new Genre();
genrefromDb.Name = DtoGenre.Name;
genrefromDb.Id = DtoGenre.Id;
game = new Game() { Name = "Integration Test Game", Genre = genrefromDb };
}
开发者ID:theklausster,项目名称:DragonsLair,代码行数:26,代码来源:GameIntegrationTest.cs
示例17: 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
示例18: GetCreatedNegotiatedContentResult
public CreatedNegotiatedContentResult<IEnumerable<Figure>> GetCreatedNegotiatedContentResult()
{
UrlHelper helper = new UrlHelper(Request);
IDictionary<string, object> route = new Dictionary<string, object>();
route["controller"] = "Figure";
route["action"] = "GetAll";
return new CreatedNegotiatedContentResult<IEnumerable<Figure>>(new Uri(helper.Link("DefaultApi", route)), FigureManager.Figures, this);
}
开发者ID:BarlowDu,项目名称:WebAPI,代码行数:8,代码来源:FigureController.cs
示例19: Enrich
private void Enrich(Car car, UrlHelper url) {
string selfUrl = url.Link(
Constants.DefaultHttpRoute,
new { controller = "cars", id = car.Id });
car.AddLink(new SelfLink(selfUrl));
}
开发者ID:mahf,项目名称:ASPNETWebAPISamples,代码行数:8,代码来源:CarResponseEnricher.cs
示例20: LegacyTreeController
public LegacyTreeController(XmlTreeNode xmlTreeNode, string treeAlias, string currentSection, UrlHelper urlHelper)
{
_xmlTreeNode = xmlTreeNode;
_treeAlias = treeAlias;
_currentSection = currentSection;
_rootDisplay = xmlTreeNode.Text;
Url = urlHelper;
}
开发者ID:phaniarveti,项目名称:Experiments,代码行数:8,代码来源:LegacyTreeController.cs
注:本文中的System.Web.Http.Routing.UrlHelper类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论