C#MVC如何将根URL映射到特定视图 [英] c# mvc how to map the root url to a specific view

查看:244
本文介绍了C#MVC如何将根URL映射到特定视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有DefaultController的mvc应用程序,该应用程序映射到index.cshtml 所以

I have an mvc app with a DefaultController which maps to index.cshtml so

http://localhost:<port>/Default/Index

正常工作. 但是默认的根页面:

works fine. but the default root page:

http://localhost:<port>/

没有映射到任何东西. 如何将其映射到我的默认值/索引?

is not mapped to anything. How can I map it to my Default/Index?

这是我的RouteConfig.cs:

Here is my RouteConfig.cs:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace MVC5_HttpClientTest_F45
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

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


        }
    }
}

推荐答案

将默认地图"路线控制器更改为

Change your Default Map route controller to

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

这篇关于C#MVC如何将根URL映射到特定视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆