gpt4 book ai didi

asp.net-mvc-3 - Url.RouteUrl 返回空

转载 作者:行者123 更新时间:2023-12-04 17:24:20 33 4
gpt4 key购买 nike

我正在尝试获取完整的 URL,但是 RouteUrl正在返回空。

在 View 中,我是这样调用的:

alert('@Url.RouteUrl("Api", new { controller = "Parametros", id = "" })');

这是我的路线配置:
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

routes.MapHttpRoute(
name: "Api",
routeTemplate: "api/{controller}/{id}",
defaults: new { id = RouteParameter.Optional }
);

routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Usuario",
action = "Login", id = UrlParameter.Optional }
);
}

和我的 Controller :
public class ParametrosController : ApiController
{
ISistemaService _sistemaService;
public ParametrosController(Empresa empresa, ISistemaService sistemaService)
{
_sistemaService = sistemaService;
}


public PagedDataModel<ParametroDTO> Get(
[FromUri]ParametroFiltro filter, int page, int pageSize)
{
int total = 0;
var list = _sistemaService.Paging(filter, page, pageSize, out total);
return new PagedDataModel<ParametroDTO>(page, pageSize, total, list);
}

public ParametroDTO Get(string codigo)
{
return _sistemaService.GetParametroPorCodigo(codigo);
}
}

最佳答案

添加 httproute = ""routeValues :

alert('@Url.RouteUrl("Api",
new { httproute = "", controller = "Parametros", id = "" })');

关于asp.net-mvc-3 - Url.RouteUrl 返回空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12935172/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com