asp.net-mvc - 如何在 ASP.NET MVC 中构造 moSTLy 静态页面

标签 asp.net-mvc

我主要有静态 View 页面,例如:

http://www.yoursite.com/games/x-box-360/nba-2k-11.aspx http://www.yoursite.com/games/psp/ben-10.aspx

如何在我的 Controller 中构造它?这是我之前在游戏 Controller 中编写的代码:

[HandleError]
public class GamesController : Controller
{
    public ActionResult ben-10()
    {    
        return View();
    }
}

但由于 Controller 操作名称中的连字符,它给了我一个错误。

我该如何解决这个问题?

最佳答案

您可能需要某种“包罗万象”的路线:

"/games/{platform}/{game}"

您可以将此路由重定向到 Controller 方法:

public class GamesController : Controller
{
    public ActionResult ViewGame(string platform, string game)
    {
        // do whatever
        return View();
    }
}

关于asp.net-mvc - 如何在 ASP.NET MVC 中构造 moSTLy 静态页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3870754/

相关文章:

asp.net-mvc - Entity Framework 6.4 缺少 migrate.exe

c# - 在 C# 中运行时将字符串转换为类

asp.net-mvc - 重写规则 https ://www to https://IIS7

c# - 如何将参数传递给 ASP.NET MVC 2 中的自定义 ActionFilter?

c# - ASP.net MVC 发送邮件

javascript - 下载文件然后离开页面

c# - Linq to SQL 并在 ASP.NET MVC 5 Identity 中选择用户的项目

javascript - Jquery 检查 ModelState 是否有效

javascript - 如何创建动态分页

asp.net - 为什么 asp.net 在我登录之前执行 302?