Jed I Jed I - 2 years ago 142
C# Question

Redirecting from cshtml page

I want to redirect to a different view depending on the result of a dataset, but I keep getting returned to the page I am currently on, and can't work out why. I drop into the if statement the action gets called but once i return the view to the new page, it returns me back to the current page.


ViewBag.Title = "Search Results";
EnumerableRowCollection<DataRow> custs = ViewBag.Customers;

bool anyRows = custs.Any();
if(anyRows == false)


// redirect to no search results view



public ActionResult NoResults()
return View("NoResults");


View I cant get too..

ViewBag.Title = "NoResults";


Answer Source

Change to this:

@{ Response.Redirect("~/HOME/NoResults");}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download