urlhelper

ASP.NET MVC: Unit testing controllers that use UrlHelper

吃可爱长大的小学妹 提交于 2019-12-17 02:33:50
问题 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 pre-filled. I tried a lot of things, among others attempting to stub UrlHelper (which failed), manually creating a UrlHelper with a RequestContext that has a stubbed HttpContextBase (which failed on a RouteCollection.GetUrlWithApplicationPath call).

convert string into (object) routeValues C#

爱⌒轻易说出口 提交于 2019-12-13 06:52:27
问题 I am writing an extension function for UrlHelper. This function will accept three String parameters. First param is ACTIOn, second is CONTROLLER and third is some RANDOM STRING. example: url.customeURL("Index", "Home", "view=someview"); After accepting all these parameters, Extension function will return a URL with action, controller and a query string something like; /Home/Index?view=someview Here is my function: public static string CustomUrlAction(this UrlHelper helper, string action,

Use a variable that store image path in Razor Url.Content

谁都会走 提交于 2019-12-13 05:19:15
问题 I used a function to construct an image path dynamically like this: function () { var name = $(this).attr('id') + '_o'; var newsrc = '../../Content/HomePage/' + name + '.png'; And I want to assign the newsrc using Razor Url.Content to an image tag as its source. SO, I wish to do something like this: $(this).attr('src', '@Url.Content(newsrc)'); But VS show me red line saying that the newsrc is not exist within current context.. How can I use a variable along with Url.Content? (Note: I am using

How to inject descendant UrlHelper class into WebViewPage to enable cache busting?

笑着哭i 提交于 2019-12-11 07:43:56
问题 I've overridden UrlHelper.Content() method. Now I want my implementation to be used instead of default UrlHelper class. How can I configure MVC to tell it which class to inject into WebViewPage.Url property? Update 1: The idea is simple. Bundles support cache busting by adding timestamp query parameter to the url. I want the same functionality for single resource. UrlHelper class allows to override its Content(string) method. Consequently it is possible to take resource's timestamp into

UrlHelper extension method call encoded not executed

孤街浪徒 提交于 2019-12-11 03:36:46
问题 I created a simple extension method for the ASP.NET MVC UrlHelper. It takes no arguments as its job is to look up the name of a stylesheet file from the configuration and return a url to the stylesheet. The extension method looks roughly like this: public static string SiteStylesheet(this UrlHelper urlHelper) { var scriptFilename = UserInterfaceConfiguration.GetSection() .Mvc.SiteStylesheet; return urlHelper.Content(string.Format("~/Assets/Scripts/{0}", scriptFilename)); } And I use it like

UrlHelper extension method not working

爷,独闯天下 提交于 2019-12-11 02:05:33
问题 I'm trying to add an extension method to my MVC 2 project without success and after several hours of googling and looking here I'm at a loss. I've created a brand new MVC 2 project to make sure there was not anything weird about my existing project and I'm still facing the same problem. I'm sure this is a situation of I "can't see the forest for the trees" so any help would be greatly appreciated. Here is the code for the extension method. using System.Web.Mvc; namespace ExtensionTest.Helper

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

怎甘沉沦 提交于 2019-12-10 02:02:21
问题 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

MVC 3 Url Helper Giving Incorrect URL

不问归期 提交于 2019-12-07 12:12:29
问题 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

Extending Zend\\View\\Helper\\Url in Zend Framework 2

人盡茶涼 提交于 2019-12-06 03:10:34
I wrote a simple url view helper, that extends Zend\View\Helper\Url and attached it to the ViewHelperManager : MyNamespace\View\Helper\Url namespace MyNamespace\View\Helper; use Zend\View\Helper\Url as ZendUrl; class Url extends ZendUrl { public function __invoke($name = null, array $params = array(), $options = array(), $reuseMatchedParams = false) { $link = parent::__invoke($name, $params, $options, $reuseMatchedParams); ... return $link; } } Application\Module namespace Application; use ... class Module { public function onBootstrap(MvcEvent $mvcEvent) { $application = $mvcEvent-

First call to Url.Action on a page is slow

怎甘沉沦 提交于 2019-12-06 02:05:36
问题 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(