问题描述
我正在遵循指南here。当我请求URL http:// localhost:xxxxx / Employee /时,我想返回。但是,使用下面的代码,这将始终返回404代码。在RouteConfig.cs中,如果将"Employee/{name}"
更改为"{controller}/{name}"
,则会返回空白页面。
我在这里做错了什么?我浏览了几次本教程,但不知道有什么不同。
Global.asax
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace scratch {
public class MvcApplication : System.Web.HttpApplication {
protected void Application_Start() {
AreaRegistration.RegisterallAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
}
}
RouteConfig.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
namespace scratch {
public class RouteConfig {
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default","{controller}/{action}/{id}",new {
controller = "Home",action = "Index",id = UrlParameter.Optional
});
routes.MapRoute(
"Process","Process/{action}/{id}",new {
controller = "Process",action = "List",id = UrlParameter.Optional
});
routes.MapRoute(
"Employee","Employee/{name}",new {
controller = "Employee",action = "Search",name = UrlParameter.Optional
});
}
}
}
EmployeeController.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace scratch.Controllers {
public class EmployeeController : Controller {
public ActionResult Search(string name) {
var input = Server.HtmlEncode(name);
return Content(input);
}
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)