自定义URL在MVC不工作 [英] Customize URL in MVC not working
本文介绍了自定义URL在MVC不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Asp.net MVC新。我在我的自定义URL路由问题击中。
我创建了我的控制器命名为客户和行动DisplayCustomer。
在页面的Global.asax.cs,
I am new in Asp.net MVC. I am struck at my Customize URL Routing problem. I have created my Controller named "Customer" and action as "DisplayCustomer". In Global.asax.cs page,
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace MvcApplication1
{
// Note: For instructions on enabling IIS6 or IIS7 classic mode,
// visit http://go.microsoft.com/?LinkId=9394801
public class MvcApplication : System.Web.HttpApplication
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new
{
controller = "Customer",
action = "DisplayCustomer",
id = UrlParameter.Optional
}); // Parameter defaults//, new { Code = @"\d{1001,1002}" }
}
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
RegisterRoutes(RouteTable.Routes);
}
}
}
我不知道是什么错,它总是呈现
为
I don't know what wrong in it,it is always showing as
http://localhost:50415/Views/Customer/DisplayCustomer.aspx
而不是
http://localhost:50415/Customer/DisplayCustomer
我缺少的东西,使其这个工作?
Am I missing something to make it this to work?
推荐答案
的复制您的问题的
- 选择项目属性
- 选择网页标签
现在,请参见下面
删除了查看目录和.cshtml扩展。这是因为您设置起始页。
Removed the View Directory and .cshtml extension. This happened because you set the start Page.
选择当前页面将解决您的问题。
Selecting the Current Page will fix your issue
这篇关于自定义URL在MVC不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文