Questions tagged [urlhelper]

113 questions
171
votes
3 answers

ASP.NET MVC: Unit testing controllers that use UrlHelper

One of my controllers actions, one that is being called in an Ajax request, is returning an URL to the client side so it can do a redirection. I'm using Url.RouteUrl(..) and during my unit tests this fails since the Controller.Url parameter is not…
efdee
  • 2,255
  • 3
  • 20
  • 26
166
votes
8 answers

Call UrlHelper in models in ASP.NET MVC

I need to generate some URLs in a model in ASP.NET MVC. I'd like to call something like UrlHelper.Action() which uses the routes to generate the URL. I don't mind filling the usual blanks, like the hostname, scheme and so on. Is there any method I…
Pablo Fernandez
  • 279,434
  • 135
  • 377
  • 622
69
votes
5 answers

Redirect with CodeIgniter

Can anyone tell me why my redirect helper does not work the way I'd expect it to? I'm trying to redirect to the index method of my main controller, but it takes me www.example.com/index/provider1/ when it should route to www.example.com/provider1.…
ocergynohtna
  • 1,703
  • 2
  • 21
  • 29
28
votes
2 answers

ASP.Net Core 2.0: Creating UrlHelper without request

I'm working on creating a UrlHelper for a background worker to create callback urls, which means it's not part of a normal request where I could just ask for it through DI. In ASP.Net 5 I could just create a HttpRequest and give it the same…
Stylpe
  • 612
  • 1
  • 7
  • 16
25
votes
1 answer

ASP.NET Core UrlHelper and how it works

I'm rather new to ASP.NET Core, and right now I am trying to get a grasp on how UrlHelper works in general. In my controller, I want to create an absolute URL to another action in the same controller, e.g.…
Frederik
  • 637
  • 2
  • 8
  • 21
24
votes
4 answers

Url helper for full url in asp.net mvc-3

Writing @Url.Content("~/Something/Something.html") in razor renders /AppFolder/Something/Something.html Is there a way to render the full URL like http://www.something.com/AppFolder/Something/Something.html without atrocious hacks? (like storing…
vinczemarton
  • 7,756
  • 6
  • 54
  • 86
21
votes
2 answers

How do I Access the RequestContext Outside the Controller?

Background I am trying to move business logic out from the controllers into their own services. Controller public class AccountController : Controller { private readonly IAccountService _accountService; public…
nfplee
  • 7,643
  • 12
  • 63
  • 124
21
votes
1 answer

Generating Route Url to MVC controller action from WebAPI

I'm used to generating route URLs to other controller actions within an MVC controller action using something similar to below: public class ApplicationController : Controller { public ActionResult Index( ) { var url =…
17
votes
6 answers

Use Separate js File And use Url Helpers in it with ASP.NEt MVC 3 and Razor View Engine

I ask a similar question here and Darin Dimitrov answer that we can't use Url helper like $.ajax({ url: '@Url.Action("Index")', . . . in separate js file so what is your suggestion to use Url helper in view page and pass it to javascript, I don't…
Saeid
  • 13,224
  • 32
  • 107
  • 173
15
votes
8 answers

Rails - URL helpers not working in mailers

I tried: class MyMailer def routes Rails.application.routes.url_helpers end def my_mail @my_route = routes.my_helper ... code omitted end Also inside mailer: include Rails.application.routes.url_helpers def my_mail …
sites
  • 21,417
  • 17
  • 87
  • 146
12
votes
3 answers

Unittesting Url.Action (using Rhino Mocks?)

I'm trying to write a test for an UrlHelper extensionmethod that is used like this: Url.Action(x => x.TestAction()); However, I can't seem set it up correctly so that I can create a new UrlHelper and then assert that the returned…
Kristoffer Ahl
  • 1,661
  • 2
  • 18
  • 36
12
votes
4 answers

MVC 6 IUrlHelper Dependency Injection

I want to use IUrlHelper through dependency injection to be able to use its functionality to generate uris for different rest endpoints. I cant seem how to figure out how to create a UrlHelper from scratch because it changed in MVC 6 and MVC doesnt…
12
votes
1 answer

Using Html.ActionLink and Url.Action(...) from inside Controller

I want to write an HtmlHelper to render an ActionLink with pre-set values, eg. <%=Html.PageLink("Page 1", "page-slug");%> where PageLink is a function that calls ActionLink with a known Action and Controller, eg. "Index" and "Page". Since…
Petrus Theron
  • 27,855
  • 36
  • 153
  • 287
12
votes
4 answers

UrlHelper.Action includes undesired additional parameters

I have a method in the controller ApplicationsController, in which I need to get the base URL for an action method: public ActionResult MyAction(string id) { var url = Url.Action("MyAction", "Applications"); ... } The problem is that this…
Ant P
  • 24,820
  • 5
  • 68
  • 105
10
votes
1 answer

Mocking Controller.Url.Action(string, string, object, string) in ASP.NET MVC

I use NUnit and Moq libraries for unit testing. I need to mock overloaded Url.Action(string, string, object, string), because my controller's action uses it to get an absolute url of an Action. My try for now (look at MockUrlAction…
kasitan
  • 509
  • 4
  • 15
1
2 3 4 5 6 7 8