0

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.

2 Answers 2

2

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:

@Html.HiddenFor(model => model.ShowModalPopup, new { id = "_showModalPopup" }) //add the id attribute for added performace

and in your jquery:

$(document).ready(function()
{
    if($('#_showModalPopup').val() == 'true')
    {
        //call your jquery modal popup method
    }
});
Sign up to request clarification or add additional context in comments.

Comments

0

I'm not an expert at dotnet technology. on my point of view, server side scripting and client side scripting shall be separate.

as javascript jquery is client side and dotnet is server side.

the server will handler request and process the server script then send the output to user browser, then only jquery function happen at user side.

basically for whatever need to be execute at client browser I will put them all in view (html). jquery and javascript they will probably need to run in html with script tag.

<script type="text/javascript">
    jQuery(function(){
        //call your function here
    });
</script>

I'm not sure if I helping or I don't understand the question. I am sorry

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.