Solve:
Download the latest version of Jquery.unobtrusive-ajax.min.js file in NuGet
Ajax Asynchronous requests:
Reference JS:
<Scripttype= "Text/javascript"src= "@Url. Staticfile ("/assets/js/jquery-2.1.1.min.js ")" CharSet= "Utf-8"></Script><Scripttype= "Text/javascript"src= "@Url. Staticfile ("/assets/js/bootstrap.min.js ")" CharSet= "Utf-8"></Script><Scripttype= "Text/javascript"src= "@Url. Staticfile ("/assets/js/plugins/footable/footable.all.min.js ")" CharSet= "Utf-8"></Script><Scripttype= "Text/javascript"src= "@Url. Staticfile ("/assets/js/content.min.js ")" CharSet= "Utf-8"></Script><Scripttype= "Text/javascript"src= "@Url. Staticfile ("/assets/js/layer/layer.js ")" CharSet= "Utf-8"></Script><Scripttype= "Text/javascript"src= "~/scripts/jquery.unobtrusive-ajax.min.js"></Script>
jquery and Jquery.unobtrusive-ajax.min.js must be referenced.
<Divclass= "Row"> <Divclass= "col-sm-12 animated fadeinright">@using (Ajax.beginform ("Layerupdatestock", "Checkstock", null,new ajaxoptions {httpmethod = "Post", O nsuccess = "Tips", Onbegin = "Validatefunction"}) {@Html. Hidden ("ID") <Divclass= "Form-group"> <Divclass= "Col-sm-3">Amount:</Div> <Divclass= "Col-sm-9">@Html. TextBox ("Updatenum", NULL, new {@class = "Form-control"}) /c7></Div> </Div> <Divclass= "Form-group"> <Divclass= "Col-sm-3">Note:</Div> <Divclass= "Col-sm-9">@Html. TextBox ("Backinfo", NULL, new {@class = "Form-control"})</Div> </Div> <Divclass= "Form-group"> <Divclass= "Col-sm-12 pull-right"> <Buttonclass= "Btn btn-primary"type= "Submit"><Iclass= "fa Fa-check"></I> Submit</Button> <Buttontype= "button"ID= "Layerclose"class= "btn btn btn-primary"Data-dismiss= "Modal"><Iclass= "fa fa-close Blue"></I> Shut down</Button> </Div> </Div> } </Div> </Div>
callback function before successful return and request:
functionvalidatefunction () {if(IsNaN (' #UpdateNum '). Val ()) && $ (' #UpdateNum '). val ()! = "") {parent.layer.msg ("Content must be a number"); return false; } } functionTips (data) {if(data = = "OK") {parent.layer.msg ("Modified successfully"); Location.reload (); varindex = Parent.layer.getFrameIndex (window.name);//get the index of the current IFRAME layer firstParent.layer.close (index);//then perform the close}Else{parent.layer.msg ("Modify Failed"); } }
Background:
[HttpPost] [ValidateInput (false)] Publiccontentresult Layerupdatestock (Checkstock stock) {varModel = This. Reportdatastatics.getcheckstock (stock.id); Model. UserName= This. UserContext.LoginInfo.LoginName; Model. Updatenum=stock. Updatenum; Model. Backinfo=stock. Backinfo; This. Tryupdatemodel<checkstock>(model); This. Reportdatastatics.savechecksock (model); //Jsonresult json = new Jsonresult (); //JSON. Data = new {result= "success"}; //return JSON; returnContent ("OK"); }
Ajax.beginform prompts for errors that do not support live properties or methods