Can Response.Redirect work in a private MVC 2 void function?

I have a private void function for some verification. If my validation fails, I would like to redirect to another ActionResult and kill the process for the ActionResult that was used. Response.Redirect ("controller name") does not help. Any ideas?

[Accept(HttpVerbs.Post)]
public ActionResult NerdDinner(string Name)
{
   testName(Name);
   ...
   Return RedirectToAction("ActionResultAAA"); 
}

private void testName(string name)  
{
    if(name == null)
    {
        //Response.Redirect("ActionResultBBB");
    }
}
+5
source share
1 answer

You can use Response.Redirect wherever you want, but you need to specify the correct (relative or absolute) URL, not just the action name. However, it would be preferable to stick with the MVC pattern and do something like this:

[Accept(HttpVerbs.Post)] 
public ActionResult NerdDinner(string Name) 
{ 
   ActionResult testResult = testName(Name)
   if (testResult != null) return testResult;
   ... 
   return RedirectToAction("ActionResultAAA"); 
} 

private ActionResult testName(string name) 
{ 
    if(name == null) 
    { 
        return RedirectToAction("ActionResultBBB"); 
    } 

    return null;
}
+7
source

All Articles