为什么我不能命名MVC .net控制器会话?

时间:2015-07-31 04:49:58

标签: c# asp.net-mvc asp.net-mvc-4

这很明确但我会解释:

我正在添加以下控制器siteblahblah / sesion / inicio /并且它说我的资源不存在!

所以我使用了这样的映射路线并且它解决了,但为什么呢? Sesion名称控制器会出现问题吗?我是否以一种奇怪的方式混淆了MVC框架?

routes.MapRoute(
                name: "sesion" ,
                url: "Sesion/{action}/{id}" ,
                defaults: new { controller = "Sesion" , action = "Inicio" , id = UrlParameter.Optional }
            );

修改:UPDATE

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace MyMVCapp.Controllers
{
    public class SesionController : Controller
    {
        //
        // GET: /sesion/

        public ActionResult Inicio()
        {
            return View();
        }
    }
}

顺便说一下,没有错别字! sesion是会话的西班牙语,因此我不想为我的西班牙语用户命名我的“sesion”会话。

1 个答案:

答案 0 :(得分:-1)

你可以这样使用,

string actionName = this.ControllerContext.RouteData.Values["action"].ToString();
string controllerName = this.ControllerContext.RouteData.Values["controller"].ToString();