gpt4 book ai didi

asp.net-mvc - 访问asp.net mvc Controller ActionResult

转载 作者:行者123 更新时间:2023-12-02 10:50:40 25 4
gpt4 key购买 nike

我想访问 Controller 中的操作结果(我的controlelr是HotelController操作是Index)

(http://localhost:9001/Hotel/Index)它给出以下错误

无法找到该资源。

说明:HTTP404。您正在寻找的资源(或其依赖项之一)可能已被删除,名称更改或暂时不可用。请查看以下网址,并确保其拼写正确。

要求的网址:/酒店/索引

酒店管理员

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);

.....

主 Controller
  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);
}
}
}
}

最佳答案

根据您发布的路由配置,您的URL应使用culture,例如:

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

注意 en之前的 Hotel 。它可以是数据库中有效的任何值。

关于asp.net-mvc - 访问asp.net mvc Controller ActionResult,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15925517/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com