Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.net 如何在MVC中创建用户友好的URL?_.net_Asp.net Mvc_Asp.net Mvc 4 - Fatal编程技术网

.net 如何在MVC中创建用户友好的URL?

.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" })) {

我正在做一个MVC项目。我的要求是我需要在浏览器中显示用户友好的URL

这是我的mvc cshtml代码

@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" }