.net 如何在MVC中创建用户友好的URL?
我正在做一个MVC项目。我的要求是我需要在浏览器中显示用户友好的URL 这是我的mvc cshtml代码.net 如何在MVC中创建用户友好的URL?,.net,asp.net-mvc,asp.net-mvc-4,.net,Asp.net Mvc,Asp.net Mvc 4,我正在做一个MVC项目。我的要求是我需要在浏览器中显示用户友好的URL 这是我的mvc cshtml代码 @using (Html.BeginForm("AppointmentType", "Appointment", FormMethod.Post, new { enctype = "multipart/form-data", @id = "formAppointmentType", @class = "", ignoreThisBit = "Test-Appointment" })) {
@using (Html.BeginForm("AppointmentType", "Appointment", FormMethod.Post, new { enctype = "multipart/form-data", @id = "formAppointmentType", @class = "", ignoreThisBit = "Test-Appointment" }))
{
<div class="container">
</div>
}
我还对webapiconfig进行了更改
config.Routes.MapHttpRoute("DefaultApi", "api/{controller}/{id}/{ignoreThisBit}", new { id = RouteParameter.Optional, ignoreThisBit = RouteParameter.Optional }
在这两个地方尝试后,我看到我的URL显示为http://localhost:8080/AppointmentType
仅限
我想出示考试预约表。如何执行此操作?如果需要,请尝试在routeconfig文件代码中不使用{id}:
routes.MapRoute("Resource", "{controller}/{action}/{ignoreThisBit}", new { controller = "Appointment", action = "Index", ignoreThisBit = UrlParameter.Optional });
您只需使用显式URL
/AppointmentType
routes.MapRoute(name: "Resource",
url: "AppointmentType",
defaults: new { controller = "Appointment", action = "AppointmentType" }
并将其置于默认路由之前。您可以从nuget package Manager安装nuget软件包-“小写虚线路由”。要安装小写虚线路由,请在软件包管理器控制台中运行以下命令:
PM>install Package lowercasedashedroote
有关更多详细信息和示例源代码:
routes.MapRoute(name: "Resource",
url: "AppointmentType",
defaults: new { controller = "Appointment", action = "AppointmentType" }