2016-11-10 16 views
1

私のページに404エラーが表示されます。私は何が欠けていますか?ASP.NET 4 MVCルート404

Global.asax.cs:App_StartフォルダRouteConfig.csで

protected void Application_Start() 
     { 
      AreaRegistration.RegisterAllAreas(); 
      RouteConfig.RegisterRoutes(RouteTable.Routes); 
     } 

:私は私のProductDetailController.csで

public class RouteConfig 
    { 
     public static void RegisterRoutes(RouteCollection routes) 
     { 
      routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

      routes.MapRoute(
       name: "ProductDetails", 
       url: "products/details", 
       defaults: new { controller = "ProductDetails", action = "Index" } 
      ); 

      routes.MapRoute(
       name: "Default", 
       url: "{controller}/{action}/{id}", 
       defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional } 
      ); 
     } 
    } 

public class ProductDetailsController : Controller 
    { 
     public ActionResult Index() 
     { 
      ProductModel Product = new ProductModel(); 
      //some code here 
      return View("~/Views/ProductDetails/Index.cshtml", Product); 
     } 
    } 

は私のビューが位置していますそのフォルダ構造とIndex.cshtmlと呼ばれる。

私がページを見ると、url/products/details/404エラーが表示されます。私はここで何が欠けていますか?注:これはウンブラのサイトです。

+0

ビューの既定の規則を使用してみてください。 'Return View(Product);' – Nkosi

+1

あなたはMVCの規則に従って正しいフォルダにファイルを置いていますか?私はあなたのコードを構築し、私は問題はなかった。ファイルの場所を再訪することをお勧めします。 – Ismael

+0

私はControllersフォルダにProductDetailsController.csを持っています。私のView Index.cshtmlは、ViewsフォルダのProductDetailsというサブフォルダにあります。 RouteConfig.csはApp_Startフォルダにあります。 – user2928262

答えて

1

Umbracoので、カスタムルートを作成するためにUmbracoをovverideするすべてのルートを引き継ぐRoutingHandlerというクラスを作成しますApp_Startフォルダに次のコードを入力します。

using System.Web.Mvc; 
using System.Web.Routing; 
using Umbraco.Core; 

    public class RoutingHandler : ApplicationEventHandler 
    { 
     protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext) 
     { 
      RegisterCustomRoutes(); 
     } 

     private static void RegisterCustomRoutes() 
     { 
      RouteTable.Routes.MapRoute(
       name: "ProductDetails", 
       url: "products/details", 
       defaults: new { controller = "ProductDetails", action = "Index" } 
      ); 
     } 
    } 
0

は一例として試してみてください:EDIT:このキャストでマルチは私のビューMulti.cshtmlの名前です

public ActionResult Index(string playerId) 
    { 
     var model = new MultiPlayerLabelModel(); 

     try 
     { 
      var player = ServiceFactory.GetPlayerService().GetPlayer(playerId); 
      model = ServiceFactory.GetLabelService().GetLabelModels(player.Position, null); 
     } 
     catch (Exception) 
     { 
      LogService.Log.Error("Failed to generate label for player"); 
     } 

     return View("Multi", model); 
    }