为什么我不能命名MVC .net控制器会话? [英] Why I can't name a MVC .net controller session?

查看:76
本文介绍了为什么我不能命名MVC .net控制器会话?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是很明确的,但我会解释:

This is pretty explicit but I will explain:

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

I am adding the following controller siteblahblah/sesion/inicio/ and it says my resource don't exist!

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

So I used a mapped route like this and it worked out, but why? Sesion name controller gives problems? Am I confusing MVC framework in a strange way?

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

更新

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是会话的西班牙语单词,因此我不想为西班牙语用户的会话"用英语命名会话.

By the way there's no typos! sesion is the spanish word for session so I don't want to name session in English for my "sesion" for my spanish users.

推荐答案

您可以像这样使用

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

这篇关于为什么我不能命名MVC .net控制器会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆