如果MVC URL中没有指定控制器名称? [英] If there is no controller name specified in MVC URL?
本文介绍了如果MVC URL中没有指定控制器名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
在MVC模型模式中,当URL中没有指定控制器名称时会发生什么,例如www.sampleapplication.com。在浏览器中提供此URL后会发生什么?
如何路由到默认值...应用程序中是否会发生这种情况?
Hi all,
In a MVC model pattern what happens when no controller name is specified in the URL, for example..www.sampleapplication.com. What happens after this URL is given in browser ?
how will it route to the default one..where does this happens in the application ?
推荐答案
您的routeconfig将包含类似
的代码
Your routeconfig will have code like
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
这意味着如果没有给出控制器,则使用Home,如果没有操作,则使用Index。所以/使用/ Home / Index,/ MyController将使用/ MyController / Index
This means that if no controller is given then use Home and if no action then use Index. So "/" uses "/Home/Index", and "/MyController" will use "/MyController/Index"
这篇关于如果MVC URL中没有指定控制器名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文