即使经过其他几十个类似的问题,我也无法完成这项工作。这是我的控制器(使用实体框架创建)
namespace mypage.Controllers
{
[RoutePrefix("Booking")]
public class BookingsController : BaseController
{
private mypageContext db = new mypageContext();
// GET: Bookings
public ActionResult Index()
{
var model = db.Bookings.ToList();
//model.Find()
return View(model);
}
// etc.
我的global.asax
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
Database.SetInitializer<mypageContext>(new DropCreateDatabaseIfModelChanges<mypageContext>());
}
}
和routeconfig.cs
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapMvcAttributeRoutes();
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
打开http://localhost:xxxxx/Booking时,我总是得到404 但这有效http://localhost:xxxxx/Bookings
还有其他地方需要检查吗?
PS:BaseController
只是空的
public abstract class BaseController : Controller
{
}
修改
但是,如果我添加而不是RoutePrefix 常规前缀,它根本不起作用
[Route("Booking/New")]
public ActionResult Edit(int? id)
答案 0 :(得分:2)
如果为控制器指定PHAssetCollectionSubtypeAlbumCloudShared
属性,则需要为操作指定Route
属性。
RoutePrefix