On the page:
@using (Ajax.beginform ("Login","User",NewAjaxoptions () {HttpMethod ="Post", onsuccess ="Afterok" })){<input ... Some forms<input type="checkbox"Id="Ckbrecord"Name="Ckbrecord" checked="checked"Value="true">remember me, next time do not login Oh! <input type="Submit"Value="Submit"/>}
ls|
<script>function Afterok (data) {vararr = Data.split (":"); if(arr[0] =="OK") { if(arr[1] =="Print Manager") Window.location.href="/admin/print"; Else if(arr[1] =="Insert") Window.location.href="/user/edituserinfo"; Elsewindow.location.href="/admin/report"; } Else $("#showMsg"). Text (arr[1]). Closest (". Row"). Removeclass ("Hidden"); }</script>
Controller
Publicactionresult Login (user user) {if(string. IsNullOrEmpty (user. Name) | |string. IsNullOrEmpty (user. PWD)) {returnContent ("No: Please enter the complete, cannot be empty! "); } user. Loginip=Request.UserHostAddress.ToString (); User. Registertime=DateTime.Now; Dao. Updateusertocurrentbase (user);//update only the data obtained from the digital campus into the current libraryUser Dbuser=DAO. Getuserbyname (user); varRecord = request["Ckbrecord"]. ToBoolean (); Setcookie (record, user); session["UserInfo"] =Dbuser; returnContent ("OK:"+Dbuser. Rank); }
Of course I prefer the AJAX submission form directly using jquery
$.ajax ({cache:true, type:"POST", Url:ajaxcallurl, data:$ ('#yourformid'). Serialize (),//your formid. Async:false, error:function (Request) {alert ("Connection Error"); }, Success:function (data) {$ ("#commonLayout_appcreshi"). Parent (). HTML (data); } });
Example of an AJAX submission form in MVC