0

我要訪問控制器操作的結果(我controlelr是HotelController行動是指數)訪問asp.net的MVC控制器的ActionResult

http://localhost:9001/Hotel/Index)它提供了以下錯誤

的資源不能被發現。

說明:HTTP 404.您正在查找的資源(或其某個依賴項)可能已被刪除,名稱已更改或暫時不可用。請檢查以下網址並確保它拼寫正確。

請求的URL:/酒店/指數

酒店控制器

public class HotelController : Base.BoxyController 
    { 
     protected override void OnActionExecuting(ActionExecutingContext filterContext) 
     { 
      base.OnActionExecuting(filterContext); 

      ViewBag.Title = "SonDakka - Otel"; 
     } 

     public ActionResult Index(string culture) 
     { 

.........

BoxyController

public class BoxyController : MainController 
    { 
     protected override void OnActionExecuting(ActionExecutingContext filterContext) 
     { 
      base.OnActionExecuting(filterContext); 

..... .....

馬inController

public class MainController : SiteController 
    { 
     protected override void OnActionExecuting(ActionExecutingContext filterContext) 
     { 
      base.OnActionExecuting(filterContext); 

......

SiteController

[ExitHttpsIfNotRequired] 
    public class SiteController : Controller 
    { 
     public Account Me { get; set; } 

     protected override void OnActionExecuting(ActionExecutingContext filterContext) 
     { 

.......

,這是我的Global.asax

using System; 
using System.Data.Entity; 
using System.IO; 
using System.Linq; 
using System.Web.Mvc; 
using System.Web.Routing; 
using Tourism.Data; 
using Tourism.Data.Mvc.Authorization; 
using Tourism.Data.Mvc.Routing; 

namespace Tourism 
{ 
    public class MvcApplication : System.Web.HttpApplication 
    { 
     public static void RegisterGlobalFilters(GlobalFilterCollection filters) 
     { 
      filters.Add(new HandleErrorAttribute()); 
     } 

     public static void RegisterRoutes(TourismContext db, RouteCollection routes) 
     { 
      routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); 

      var cultures = db.Cultures.Select(c => c.Code).ToArray(); 

      routes.MapRoute 
       (
        "Ajax", 
        "{culture}/{controller}/{action}/{id}", 
        new { id = UrlParameter.Optional }, 
        new { culture = new ArrayRouteConstraint(true, cultures), controller = new ArrayRouteConstraint(true, "Ajax") } 
       ).RouteHandler = new GlobalizedRouteHandler(); 

      routes.Add 
       (
        "Page", 
        new GlobalizedPageRoute 
         (
          "{culture}/{path}", 
          null, 
          new RouteValueDictionary { { "culture", new ArrayRouteConstraint(true, cultures) } }, 
          new GlobalizedRouteHandler() 
         ) 
       ); 

      routes.Add 
       (
        "Route", 
        new GlobalizedRoute 
         (
          "{culture}/{path}/{slug}/{id}", 
          new RouteValueDictionary { { "culture", UrlParameter.Optional }, { "path", UrlParameter.Optional }, { "slug", UrlParameter.Optional }, { "id", UrlParameter.Optional } }, 
          new RouteValueDictionary { { "culture", new ArrayRouteConstraint(false, cultures) } }, 
          new GlobalizedRouteHandler() 
         ) 
       ); 
     } 

     protected void Application_Start() 
     { 
      Database.SetInitializer<TourismContext>(null); 

      using (var db = new TourismContext()) 
      { 
       #if !DEBUG 

       if (!db.Database.CompatibleWithModel(true)) 
       { 
        System.Web.HttpRuntime.UnloadAppDomain(); 

        throw new Exception("Veritabanı değişikliği tespit edildi."); 
       } 

       #endif 

       AreaRegistration.RegisterAllAreas(); 

       RegisterGlobalFilters(GlobalFilters.Filters); 

       RegisterRoutes(db, RouteTable.Routes); 
      } 
     } 

     protected void Application_PostAuthenticateRequest() 
     { 
      if (Request.IsAuthenticated) 
      { 
       Context.User = System.Threading.Thread.CurrentPrincipal = 
        new AuthorizationPrincipal(Context.User.Identity); 
      } 
     } 
    } 
} 
+1

「請求的URL:/酒店/謝謝你」 - 這是錯誤的一部分?如果是的話那麼你有沒有所謂的「感謝」的方法? – 2013-04-10 12:20:29

+0

我應該更新的問題...我嘗試訪問索引提示錯誤比我嘗試感謝它還是給了一些錯誤...的http://本地主機:9001 /酒店/指數 – user1688401 2013-04-10 14:28:15

+0

您可以發佈您的路由配置?請編輯您的文章並加入。 – 2013-04-10 15:03:25

回答

0

基於路由的配置你貼,您的網址應與culture,例如:

http://localhost:9001/en/Hotel/Index 

通知Hotelen。它可以是任何在數據庫中有效的值。

3

因爲這是由於剃刀引擎無法在酒店控制器中查找感謝行動。你需要做一個感謝的動作,在酒店控制器這樣的:

public class HotelController : Base.BoxyController 
{ 

public ActionResult Thanks(string culture) 
{ 
    return View(); 
} 

} 

,並且確保創建酒店文件夾中查看與您的HTML代碼。

+0

我更新了問題...我編輯了我的問題錯誤...我的HotelController有感謝和索引操作... – user1688401 2013-04-10 14:30:31

+0

http:// localhost:9001 /酒店/索引我把這種,這給錯誤....和HotelController具有指標作用的結果.....公衆的ActionResult指數(串文化).... – user1688401 2013-04-10 14:33:28

相關問題