Reputation: 3447
I wish to display a Javascript type popup to alert the user that he has to fill in some additional data in a previous View before continue processing this View, and then actually redirect the user to that View.
At the moment my code is as follows :-
if (viewModel.compData.GG != "")
CalcGradingPoints();
else
{
Response.Write(@"<script language='javascript'>alert('You have to Select a Grading before doing this calculation');</script>");
return RedirectToAction("Index", "Grading");
}
return View(viewModel);
It is redirecting correctly, however I cannot see the error message, so for the user, it is like he is stuck on the first View and not moving.
How can I display an error message, allow the user to confirm that he saw the message by clicking the message, and then redirecting?
Thanks for your help and time
Upvotes: 0
Views: 2439
Reputation: 14440
You should use the confirm()
function : http://www.javascripter.net/faq/confirm.htm
usage :
if (confirm("Your question")) {
window.location = "http://www.google.com/" //redirect HERE
}
Upvotes: 1
Reputation: 3447
Actually I thought there was an easy way to do it. I have taken a different approach and set everything on the first View to a default value, so that the second View will never be blank.
Thanks for your help
Upvotes: 0
Reputation: 17288
RedirectToAction
is 302 HTTP redirect, you will never see anything with Response.Write
. I also had same scenario and create for with logic separate view, where I show message and then redirect user. My model contain: title, message, controller, action and etc. Then you just fill view and create link with @Url.Action
.
meta example:
<meta http-equiv="REFRESH" content="0;url=http://www.your-link.com">
The content="0; may be changed to the number of seconds you want the browser to wait before redirecting.
Upvotes: 0