Url.Action does not give me the actual url

I have a view called "Index". There is a search bar on the page, and when you click the submit button, I have a Javascript redirect:

var alerted='@url';
var url=alerted + "/" + $("#SearchText").val();

In the Razor view url, this is a variable defined asvar url = Url.Action("Index", "Search");

But in Javascript the warning outputs "/" are displayed. I have no idea why this is. If I change it to a different kind of controller, it will be fine. But if I call Index from Index, it won’t give me anything. What gives? I need him to give me the url of the page I'm on.

+3
source share
1 answer

URL. URL- - "/".

Url.Action("Index", "Search", null, Request.Url.Scheme)

URL.

gloabal.asax , , , :

routes.MapRoute(
                "Default", // Route name
                "{controller}/{action}/{id}", // URL with parameters
                new { controller = "Search", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);

/, , . , .

@Url.Action("Index", "Search")

"/Search/Index", "/" URL-. , , , .

routes.MapRoute(
                "Index", // Route name
                "Search/Index/{id}", // URL with parameters
                new { controller = "Search", action = "Index", id = UrlParameter.Optional } // Parameter defaults);

Url.Action("Search","Index") "/Search/Index" URL-, . , , , .

+5

All Articles