【问题标题】:Show View in the main page itself (eg: sample.com) in asp.net mvc在 asp.net mvc 中的主页本身(例如:sample.com)中显示视图
【发布时间】:2021-01-26 08:48:21
【问题描述】:

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

【问题讨论】:

    标签: asp.net asp.net-mvc visual-studio asp.net-mvc-5


    【解决方案1】:

    你必须设置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

    【讨论】:

    • 如果答案对您不起作用,请告诉我。 @Sangeeth Sajan
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-09-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多