More CR feedback on URL generation
This commit is contained in:
parent
77a7bb58a6
commit
00f15669dc
|
|
@ -19,5 +19,15 @@ namespace MvcSample
|
|||
{
|
||||
return Url.Route(new { controller = "Home", action = "Details" });
|
||||
}
|
||||
|
||||
public string Link1()
|
||||
{
|
||||
return Url.Action("Index", "Home");
|
||||
}
|
||||
|
||||
public string Link2()
|
||||
{
|
||||
return Url.Action("Link2");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
{
|
||||
var viewContext = new ViewContext(context.HttpContext, ViewData, _serviceProvider)
|
||||
{
|
||||
Url = new DefaultUrlHelper(context.HttpContext, context.Router, context.RouteValues),
|
||||
Url = new UrlHelper(context.HttpContext, context.Router, context.RouteValues),
|
||||
};
|
||||
await view.RenderAsync(viewContext, writer);
|
||||
}
|
||||
|
|
@ -49,7 +49,7 @@ namespace Microsoft.AspNet.Mvc
|
|||
ViewEngineResult result = await _viewEngine.FindView(actionContext, viewName);
|
||||
if (!result.Success)
|
||||
{
|
||||
string locationsText = String.Join(Environment.NewLine, result.SearchedLocations);
|
||||
string locationsText = string.Join(Environment.NewLine, result.SearchedLocations);
|
||||
const string message = @"The view '{0}' was not found. The following locations were searched:{1}.";
|
||||
throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, message, viewName, locationsText));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,12 +61,12 @@ namespace Microsoft.AspNet.Mvc
|
|||
}
|
||||
else if (prop.Name == "Url" && prop.PropertyType == typeof(IUrlHelper))
|
||||
{
|
||||
var generator = new DefaultUrlHelper(
|
||||
var urlHelper = new UrlHelper(
|
||||
actionContext.HttpContext,
|
||||
actionContext.Router,
|
||||
actionContext.RouteValues);
|
||||
|
||||
prop.SetValue(controller, generator);
|
||||
prop.SetValue(controller, urlHelper);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@ using Microsoft.AspNet.Routing;
|
|||
|
||||
namespace Microsoft.AspNet.Mvc
|
||||
{
|
||||
public class DefaultUrlHelper : IUrlHelper
|
||||
public class UrlHelper : IUrlHelper
|
||||
{
|
||||
private readonly HttpContext _httpContext;
|
||||
private readonly IRouter _router;
|
||||
private readonly IDictionary<string, object> _ambientValues;
|
||||
|
||||
public DefaultUrlHelper(HttpContext httpContext, IRouter router, IDictionary<string, object> ambientValues)
|
||||
|
||||
public UrlHelper([NotNull] HttpContext httpContext, [NotNull] IRouter router, [NotNull] IDictionary<string, object> ambientValues)
|
||||
{
|
||||
_httpContext = httpContext;
|
||||
_router = router;
|
||||
|
|
@ -5,22 +5,22 @@ namespace Microsoft.AspNet.Mvc
|
|||
{
|
||||
public static string Action([NotNull] this IUrlHelper generator)
|
||||
{
|
||||
return generator.Action(null, null, null);
|
||||
return generator.Action(action: null, controller: null, values: null);
|
||||
}
|
||||
|
||||
public static string Action([NotNull] this IUrlHelper generator, string action)
|
||||
{
|
||||
return generator.Action(action, null, null);
|
||||
return generator.Action(action: action, controller: null, values: null);
|
||||
}
|
||||
|
||||
public static string Action([NotNull] this IUrlHelper generator, string action, object values)
|
||||
{
|
||||
return generator.Action(action, null, values);
|
||||
return generator.Action(action: action, controller: null, values: values);
|
||||
}
|
||||
|
||||
public static string Action([NotNull] this IUrlHelper generator, string action, string controller)
|
||||
{
|
||||
return generator.Action(action, controller, null);
|
||||
return generator.Action(action: action, controller: controller, values: null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue