0

我有这个现有的应用程序,现在用户希望我添加一个新页面。但 URL 应该相同。即已经有一个视图名称索引。

http://www.localhost/Index?mdn=&Mdn wdate=&Wdate

现在用户希望我添加一个名为Count的新视图,但他们希望 url 应该是这样的。(除了一个查询字符串。)

http://www.localhost/Index?mdn=&Mdn count=&Count

我是 asp.net MVC 的新手。请帮忙谢谢。

4

2 回答 2

1

在您的控制器操作中,您可以选择要渲染的视图:

public ActionResult Index(...)
{
  if (...)
    return View("Count");

  return View(); // returns the default view (in this case "Index")
}
于 2013-08-15T07:07:42.427 回答
1

有几种方法可以实现这一目标。一种方法是使用RedirectToAction()

public ActionResult Index(string count)
    {
        if (count == "Count")
            return RedirectToAction("newActionMethod"); 

        // ... other codes ...
        return View();
    }
于 2013-08-15T07:26:11.360 回答