You can redirect to an external URL by using Redirect Method() or via Json Result.
Asp.net MVC redirect to URL:
You can do URL redirect in mvc via Controller’s Redirect() method. The following example, I have given redirection to google page.
public ActionResult Index()
{
return Redirect("http://www.google.com");
}
JQuery ajax redirect:
You cannot perform server side redirect from jQuery Ajax response.So that you should return JsonResult with a new URL and perform response redirect with JavaScript’s window.location property.
<script type="text/javascript">
$.post("@Url.Action("Redirect")", function (data) {
window.location = data.url;
});
</script>
public ActionResult Redirect()
{
// ...
return Json(new { url = "http://www.yahoo.com" });
}
Post your comments / questions
Recent Article
- ImportError: cannot import name 'url' from 'django.conf.urls' - Django Error
- How to Enable Virtualization in BIOS Security Settings in Intel Processors For Android Studio?
- Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that depend on it.
- AttributeError: 'NoneType' object has no attribute 'get_text' - Python
- ModuleNotFoundError: No module named 'openpyxl' - Python
- How to get thumbnail from vimeo video URL in Python?
- Remove all special characters, punctuation except spaces from string - Python
- OSError: cannot write mode RGBA as JPEG- Python
Related Article