$.ajax ({//URL: ' Http://192.168.0.102/webApiDemo/api/WebApiTest/PostStudentInforOnePara ', //URL: "Http://localhost/webapidemo/api/WebApiTest/PostStudentInforOnePara",URL: "Userlogin/login", type:' GET ', data: {bname:txtbname, PSW:TXTPSW},//a parameter, you must write this, Webapi in the HTTP request body inside to take parameters to fetch. ContentType: "JSON", Async:true,//AsynchronousSuccessfunction(data)//the callback method after success { if(data = "suscess")) window.location.href = "@Url. Action (" Index "," Home ");//Can jump.}, Error:function() {alert (Failed "); //window.location.href = "easyuiloutmain.aspx";//Can jump.}
Window.location.href = "@Url. Action (" Index "," Home ") is interpreted by the browser as Window.location.href ="//";//write directly to the controller you want to jump to.
Controller:
PublicIactionresult Login (stringBname,stringPSW) { if(!modelstate.isvalid) {returnView (); } if(string. IsNullOrEmpty (bname)) {bname= request.query["bname"]. ToString (); } if(string. IsNullOrEmpty (PSW)) {PSW= request.query["PSW"]. ToString (); } if(Bname. Equals ("Longdb") && PSW. Equals ("123")) { returnJson ("suscess"); } returnView (); }
. NET MVC uses jquery Ajax after successful page jumps.