Ben P
Ben P

Reputation: 197

Calling Multiple View based on static URL in ASP.NET MVC

I have this existing application now user wants me to add a new page.But URL should be same. i.e.there is already a view name Index.

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

Now user wants me to add a new view named Count but they wants url should be like this.(except one query string.)

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

I am new in asp.net MVC. Please help thanks.

Upvotes: 0

Views: 92

Answers (2)

Amin Saqi
Amin Saqi

Reputation: 18977

There is several ways to achieve that. One way is using RedirectToAction():

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

        // ... other codes ...
        return View();
    }

Upvotes: 1

Jens Neubauer
Jens Neubauer

Reputation: 1090

In your controller action, you can choose which view to render:

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

  return View(); // returns the default view (in this case "Index")
}

Upvotes: 1

Related Questions