0

i want to access action result in controller(my controlelr is HotelController action is Index)

(http://localhost:9001/Hotel/Index) it gives below error

The resource cannot be found.

Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

Requested URL: /Hotel/Index

Hotel controller

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

..........

MainController

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

.......

and this is my 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);
            }
        }
    }
}
4
  • 1
    "Requested URL: /Hotel/Thanks" - that is part of the error? If yes then do you have a method called "Thanks"? Commented Apr 10, 2013 at 12:20
  • i should update question... i try to access index it gives error than i try for thanks it still give some error... localhost:9001/Hotel/Index Commented Apr 10, 2013 at 14:28
  • Can you post your route config? Please edit your post and include it. Commented Apr 10, 2013 at 15:03
  • i post global.asax and include code... thanks von v. Commented Apr 10, 2013 at 16:20

2 Answers 2

3

Because this is due to Razor engine unable to find Thanks action in Hotel controller. You need to make a Thanks action with in Hotel controller like this:

public class HotelController : Base.BoxyController
{

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

}

And also make sure to create a view in Hotel folder with your html code.

Sign up to request clarification or add additional context in comments.

2 Comments

i update question...i edited my question mistake...my HotelController has thanks and Index action...
localhost:9001/Hotel/Index i call this and this give error....and HotelController has Index action result..... public ActionResult Index(string culture)....
0

Based on the route config you posted, your URL should be with culture, for example:

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

Notice the en before Hotel. It could be any value that is valid in your database.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.