Redirect to external URI from ASP.NET MVC controller

前端 未结 4 1029
Happy的楠姐
Happy的楠姐 2020-11-27 13:52

I\'m trying to redirect to external url from an action method but can\'t get it to work. Can anybody shed some light on my error?

public void ID(string id)
          


        
相关标签:
4条回答
  • 2020-11-27 14:08

    Maybe the solution someone is looking for is this:

    Response.Redirect("/Sucesso")
    

    This work when used in the View as well.

    0 讨论(0)
  • 2020-11-27 14:15

    Using JavaScript

     public ActionResult Index()
     {
        return Content("<script>window.location = 'http://www.example.com';</script>");
     }
    

    Note: As @Jeremy Ray Brown said , This is not the best option but you might find useful in some situations.

    Hope this helps.

    0 讨论(0)
  • 2020-11-27 14:25

    If you're talking about ASP.NET MVC then you should have a controller method that returns the following:

    return Redirect("http://www.google.com");
    

    Otherwise we need more info on the error you're getting in the redirect. I'd step through to make sure the url isn't empty.

    0 讨论(0)
  • 2020-11-27 14:26

    Try this (I've used Home controller and Index View):

    return RedirectToAction("Index", "Home");
    
    0 讨论(0)
提交回复
热议问题