user2282567
user2282567

Reputation: 781

How can I return two views from an action?

How can I return two views from an action?

I tried as below but I got an error.

public ActionResult Page()
{
    //LINQ x expressions
    //LINQ y expressions
    if (Request.QueryString["type"] == "x")
    {
        return View(linqExpX.ToList());
    }
    else if (Request.QueryString["type"] == "y")
    {
        return View(linqExpY.ToList());
    }
}

Upvotes: 0

Views: 104

Answers (1)

tukaef
tukaef

Reputation: 9224

Not all parts of your code return a value..

Try this code:

public ActionResult Page()
{
    //LINQ x expressions
    //LINQ y expressions
    if(Request.QueryString["type"] == "x")
    {
        return View(linqExpX.ToList());
    }
    else if(Request.QueryString["type"] == "y")
    {
        return View(linqExpY.ToList());
    }

    return someDefaultView; 
}

Upvotes: 2

Related Questions