在 asp.net mvc 中在主页面本身显示视图(例如:sample.com)

Show View in the main page itself (eg: sample.com) in asp.net mvc

我需要在主页上显示我的视图。假设我有一个名为“Sample”的应用程序。当用户来到 sample.com 时,它将转到示例。com/Home/Index。是否有任何 way/method 可以像我们在纯 HTML 页面中那样在 sample.com 本身中显示视图?尽管我已经进行了几次 google 搜索,但我最终还是得到了误导性内容。

您必须设置 RouteConfig:

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

结果:

http://localhost:51225/Home/Index/1 => Index.html
http://localhost:51225/Home/Index/ => Index.html
http://localhost:51225/Home/ => Index.html
http://localhost:51225/ => Index.html

http://sample.com/Home/Index/1 => Index.html
http://sample.com/Home/Index/ => Index.html
http://sample.com/Home/ => Index.html
http://sample.com/ => Index.html

您可以在以下位置了解更多信息: https://www.tutorialsteacher.com/mvc/routing-in-mvc