Create an action-free action URL in MVC 3

Is there a way to get the url of the code, but without a part of the application name?

I need to call Url.Action("Create", "Home")and get / home / Create, but not / AppName / home / Create.

Default map route: {controller} / {action} / {id}

The application is published in the "AppName" folder on the server and Url.Action("Create", "Home")returns / AppName / home / Create.

+4
source share
1 answer

You can use an assistant VirtualPathUtility.ToAppRelative(). For instance:

// returns /AppName/Home/Create.
var withAppNameUrl = Url.Action("Create", "Home");

// returns ~/Home/Create
var relativeToAppUrl = VirtualPathUtility.ToAppRelative(withAppNameUrl);

See MSDN .

+1
source

Source: https://habr.com/ru/post/1547740/


All Articles