Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Url.RouteUrl returning empty

I´m trying to get full URL but the RouteUrl is returning empty.

In the View, I´m calling like that:

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

Here is my routes configurations:

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 }
    );
}

and my 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);
    }
}
like image 602
will Avatar asked Oct 17 '12 13:10

will


1 Answers

Add httproute = "" to the routeValues:

alert('@Url.RouteUrl("Api",
     new { httproute = "", controller = "Parametros", id = "" })');
like image 187
Darin Dimitrov Avatar answered Oct 22 '22 02:10

Darin Dimitrov