它可以通过相同的视图路由

时间:2012-03-10 15:28:11

标签: c# asp.net-mvc asp.net-mvc-3 asp.net-mvc-routing

我创建了一个mvc3应用程序,然后在Home Controller中添加一个名为Message的新选项卡(在共享文件夹的_Layout.cshtml中),我将以下函数包含在HomeController.cs中

public string Message(string msg)
{
    return "This is my message :" + msg + " to you";
}

然后,我可以使用以下任何网址进行路由

> http://localhost:2554/Home/Message/message=some%20message
> http://localhost:2554/Home/Message
> http://localhost:2554/Home/Message/message

但是我没有在显示屏上看到msg。为什么其中三个会产生相同的视图?我应该添加什么才能使msg可见?

1 个答案:

答案 0 :(得分:1)

如果您希望通过上面显示的方法使用路线表,请在路线表中添加路线

_routeCollection.MapRoute("Message", "Home/Message/{msg}", new {controller = "Home", action = "Message", msg = ""});