I have a requirement to open a popup from an action method in controller. The action method is basically registering a user.
[HttpPost]
public ActionResult Register(RegisterModel model)
{
if (ModelState.IsValid)
{
MembershipCreateStatus createStatus;
Membership.CreateUser(model.UserName, model.Password, model.Email, null, null, true, null, out createStatus);
if (createStatus == MembershipCreateStatus.Success)
{
FormsAuthentication.SetAuthCookie(model.UserName, false /* createPersistentCookie */);
//------------------------------------------
//I need to call a jquery function from here
//------------------------------------------
return RedirectToAction("Index", "Home");
}
else
{
ModelState.AddModelError("", ErrorCodeToString(createStatus));
}
}
return View(model);
}
The jquery function, present in the view, would just make a hidden DIV, visible, and set the opacity, etc, to represent a popup.
I need to call such a jquery function from the controller’s action method shown above.
You cannot call client side script from the server. However, you can set indicators on the server side that the client side can look at to determine it’s action.
I would set a bool in the model called ShowModalPopup and when createStatus == MembershipCreateStatus.Success, set that bool to true.
Now, on your view, write out the indicator:
and in your jquery: