开发者

ASP .NET MVC. Ajax.BeginForm OnSuccsess can't find a javascript function

I have a IQuery dialog with an ajax form inside it. I need to close this dialog on succsess. Here is my form code:开发者_开发技巧

   using (Ajax.BeginForm("Add", "User", new AjaxOptions { HttpMethod = "post", OnSuccess = "userRegisterDialogCallback" }))
   {%>
       // here goes form code
  <%}%>

Here is the generated html:

<script type="text/javascript">
    function userRegisterDialogCallback() {
    $("#userRegisterDialog").dialog("close");}
    }
</script>
<div id="userRegisterDialog" title="Регистрация">
<form action="/User/Add" id="form0" method="post" onclick="Sys.Mvc.AsyncForm.handleClick(this, new Sys.UI.DomEvent(event));" onsubmit="Sys.Mvc.AsyncForm.handleSubmit(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace, httpMethod: &#39;post&#39;, onSuccess: Function.createDelegate(this, userRegisterDialogCallback) });">
<!-- Form code goes here -->
</form>

The problem is that after submit javascript debugger says that userRegisterDialogCallback is not defined. What I am missing? Thanks in advance for your answers.


You have a script error because of one too many braces:

<script type="text/javascript">
    function userRegisterDialogCallback() {
    $("#userRegisterDialog").dialog("close");              // **}**
    }
</script>


Unobtrusive JavaScript mode is turned off. To turn unobtrusive JavaScript mode on/off by default for the entire application, you can use Web.config:

<configuration>
    <appSettings>
        <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
    </appSettings>
</configuration>

You can also turn it on or off with code:

HtmlHelper.UnobtrusiveJavaScriptEnabled = true;

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜