2016-11-05 61 views
0

我用Ajax.BeginForm表單發帖。Asp.net mvc ajax多跑一次

但是當我快速點擊按鈕不止一個。處理工作不止一個。 RefreshPosts();腳本工作時,會重置表單元素。

控制器:

public string SharePost(FormCollection form) 
{ 
     var singleUser = _repUsers.GetUserWithCookie(GetCookie(_set.userCookieName)); 
     string content = Request.Form["statusText"]; 
     _opPosts.AddPost(content, singleUser.UserId); 
     _opUsers.AddFeed(1, singleUser.UserFirstName, singleUser.UserSurName); 
     Session["PostDate"] = DateTime.Now; 
     return "Başarıyla paylaştık." + "<script> refreshPosts(); </script>"; 

} 

查看:

@using (Ajax.BeginForm("SharePost", "Post", new AjaxOptions { HttpMethod = "POST", UpdateTargetId = "result", OnSuccess = "postSuccess", LoadingElementId = "loading" })) 

回答

0

禁用上提交單擊該按鈕。這可以使用JQuery/Java Script來完成。 關於如何做到這一點,請看this example