0

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

2
  • Why not just return RedirectToAction("ShowColor", "Admin");? Commented Jun 7, 2016 at 4:30
  • Because I want to show an alert too @StephenMuecke Commented Jun 7, 2016 at 4:32

2 Answers 2

1

I believe this is due to relative paths. Something like the below should make it relative to the domain.

window.location.href='/Admin/ShowColor'
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.