【发布时间】:2014-12-10 19:33:19
【问题描述】:
我有一个只有一个控制器和一个动作的应用程序,但我想将两个值传递给该动作。我正在寻找的最终结果是一个看起来像这样的网址 http://www.example.com/parameter1/parameter2
所以我在想路由应该是这样的
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}/{name}",
defaults: new { controller = "Home", action = "Index"}
);
控制器看起来像这样
public class HomeController : Controller
{
public ActionResult Index(string id, string name)
{
return View();
}
}
但我显然错了,因为它不起作用。有谁知道在索引操作下是否有可能?
澄清一下,我希望在默认操作中有 2 个参数。我知道通过http://www.example.com/books/parameter1/parameter2/ 之类的东西是可能的,但我特别想要http://www.example.com/parameter1/parameter2/
【问题讨论】:
标签: c# asp.net-mvc