Example of an AJAX submission form in MVC

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.