Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从控制器中的操作方法调用jquery函数?_Jquery_Asp.net Mvc 3 - Fatal编程技术网

如何从控制器中的操作方法调用jquery函数?

如何从控制器中的操作方法调用jquery函数?,jquery,asp.net-mvc-3,Jquery,Asp.net Mvc 3,我需要在控制器中打开一个动作方法弹出窗口。操作方法基本上是注册用户 [HttpPost] public ActionResult Register(RegisterModel model) { if (ModelState.IsValid) { MembershipCreateStatus createStatus; Membership.CreateUser(model.UserName, model.Password,

我需要在控制器中打开一个动作方法弹出窗口。操作方法基本上是注册用户

[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);
}
视图中的jquery函数只会使隐藏的DIV可见,并设置不透明度等,以表示弹出窗口


我需要从上面显示的控制器的操作方法调用这样的jquery函数

我不是网络技术专家。 在我看来,服务器端脚本和客户端脚本应该是分开的

正如javascript一样,jquery是客户端,dotnet是服务器端

服务器将处理程序请求并处理服务器脚本,然后将输出发送到用户浏览器,然后只有jquery函数发生在用户端

基本上,无论需要在客户端浏览器上执行什么,我都会将它们全部放在视图(html)中。 jquery和javascript可能需要在带有脚本标记的html中运行

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

jQuery(函数(){
//在这里调用你的函数
});

我不确定我是在帮忙还是不明白这个问题。很抱歉,您无法从服务器调用客户端脚本。但是,您可以在服务器端设置指示符,客户端可以查看这些指示符来确定其操作

我会在名为ShowModalPopup的模型中设置一个bool,当createStatus==MembershipCreateStatus.Success时,将该bool设置为true

现在,在您的视图中,写出指示器:

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

$(document).ready(function()
{
    if($('#_showModalPopup').val() == 'true')
    {
        //call your jquery modal popup method
    }
});