Reputation: 449
I'm developing an ASP.Net MVC 5 project . I need to redirect page when I submit something. I used this Javascript code :
return Content("<script language='javascript' type='text/javascript'>alert('Edited...');window.location.href = 'ShowColor';</script>");
when I edit something in
http://localhost:56583/Admin/EditColor/27
I want redirect my page to
http://localhost:56583/Admin/ShowColor
With above code it goes to
http://localhost:56583/Admin/EditColor/ShowColor
Also I used below code according to Redirecting to action from javascript but it didn't work too :
return Content("<script language='javascript' type='text/javascript'>alert('Edited...');window.location.href = '@Url.Action('ShowColor', 'Admin')';</script>");
I have no idea how fix it. thanks for any help
Upvotes: 0
Views: 5978
Reputation: 1023
To show an alert and redirect, you need to make an anchor tag that invokes your controller action, then the controller would look something like:
public ActionResult AlertAndRedirect()
{
return Content("<script language='javascript' type='text/javascript'>alert('Good work, click to redirect.');</script>");
}
Which will pop a dialog box, then redirect you.
Upvotes: 0
Reputation: 196
I believe this is due to relative paths. Something like the below should make it relative to the domain.
window.location.href='/Admin/ShowColor'
Upvotes: 1