urlhelper

MVC 3 Url Helper Giving Incorrect URL

只愿长相守 提交于 2019-12-05 23:15:14
I am developing a MVC 3 application for a corporate intranet site and I am having some issues with the URL helper sometimes not producing correct URLs. The application is being accessed through an access manager application that is controlled by our IT department which basically provides a standardized URL so that the user does not need to know any information about the server. For example, to access the application directly on the server, I would visit: http://philsserver/App Through the access manager, I would use the URL provided by the IT department: http://secureintranet/PHILSAPP/App/ I

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

笑着哭i 提交于 2019-12-05 00:06:53
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 HtmlHelper and UrlHelper do not exist inside a Controller or class, how do I get the relative URL to an action from inside a class? Update: Given the additional three years of accrued experience I have now, here's my advice: just use Html.ActionLink("My Link", new { controller = "Page", slug = "page-slug" }) or better yet, <a href="@Url.Action("ViewPage", new

How do I Access the RequestContext Outside the Controller?

旧街凉风 提交于 2019-12-04 15:53:22
问题 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 AccountController(IAccountService accountService) { _accountService = accountService; } .... } I'm using Unity to inject dependencies. I'd like to use the Url.GenerateUrl() helper method within the implementation of IAccountService but Url is a property against the controller. I looked

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

一世执手 提交于 2019-12-04 10:19:19
问题 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 the protocol and domain in the AppConfig , and concatenate the string to it) Is there a helper like @Url.FullPath("~/asdf/asdf") or similar? 回答1: The @Url.RouteURL() does not quiet answer this question. It does work for named routes but falls short

First call to Url.Action on a page is slow

允我心安 提交于 2019-12-04 05:16:10
I have a performance issue with a fairly simple ASP.MVC view. It's a log-on page that should be almost instant, but is taking about half a second. After a lot of digging it looks like the problem is the first call the Url.Action - it's taking around 450ms (according to MiniProfiler ) but that seems insanely slow. Subsequent calls to Url.Action are taking <1ms, which is more in line with what I would expect. This is consistent whether I use Url.Action("action", "controller") or Url.Action("action") , but doesn't seem to happen if I use Url.Content("~/controller/action") . This also happens when

How do I Access the RequestContext Outside the Controller?

空扰寡人 提交于 2019-12-03 10:52:49
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 AccountController(IAccountService accountService) { _accountService = accountService; } .... } I'm using Unity to inject dependencies. I'd like to use the Url.GenerateUrl() helper method within the implementation of IAccountService but Url is a property against the controller. I looked at the MVC source to see how this is done but it requires me to access the RequestContext from outside

UrlHelper.Action includes undesired additional parameters

喜夏-厌秋 提交于 2019-11-30 02:04:11
问题 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 includes the string id from the current route data, when I need the URL without (the URL is used to fetch content from a CMS on a URL-based lookup). I have tried passing null and new { } as the routeValues parameter to no avail. The matching route is as

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

我怕爱的太早我们不能终老 提交于 2019-11-28 23:19:41
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 want to use hard code url, I need to find it with Url helper.? Use a hidden field to store your url, then use javascript to read the hidden field, then use that in your code. That way you can keep the JS file separate to the view. Something like this: //In Your View @Html.Hidden("MyURL", Url.Action("Index")) //In Your JS var myUrl = $("#MyURL").val();

Generating Route Url to MVC controller action from WebAPI

Deadly 提交于 2019-11-28 10:45:49
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 = Url.RouteUrl("routename", new { controller = "Application", Action = "Index2" , other="other" }); } public ActionResult Index2( string other) { } } But I also need to be able to generate URLs to MVC controller actions from within webapi too, How would I go about doing this? There seems to be a UrlHelper property on the APIController but I cant find any examples of how to use

ASP.Net Core 2.0: Creating UrlHelper without request

可紊 提交于 2019-11-28 08:58:19
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 HttpConfiguration I used to build my app, but in ASP.Net Core 2.0 the UrlHelper depends on a full ActionContext which is a bit harder to craft. I have a working prototype, but it's using a nasty hack to smuggle the route data out of the application startup process. Is there a better way to do this? public class Capture { public IRouter Router { get; set; }