asp.net MVC foreground View page several ways to pass data to the controller controller __.net

Source: Internet
Author: User

https://blog.csdn.net/ydm19891101/article/details/44336951

Previous article asp.net mvc @model and model explain how the background controller to the front page to pass data, and today we will explain the front view page back to the table controller controller to pass data several ways. These are some of the ways I use in practice and summed up, if that place is wrong or have deficiencies, you are welcome to point out and give constructive advice, and learn together.

1, asynchronous mode

In actual project development, we often need to submit data asynchronously, we can get some important information without submitting the current page. This will neither waste network resources nor cause server load. The main asynchronous methods are Ajax, post, get three kinds of

(1) Ajax Way

[javascript]  View Plain  copy/* To determine if the user has logged on to */            $ (function  ()  {                $.ajax ({                    type:  "POST",                    url:  "/MONTHWIN/INDEX/12",                    data:{"name": Name, "Sex":sex},                    dataType:  ' JSON ',                    success: function  (Result)  {                        if  (result == true)  {                            isLogin = true;                        }                         else {                            isLogin = false;                        }                    }               &NBSP});           &NBSP})   

(2) Post mode

[javascript]  View Plain  copy $.post (url, {  "username": username,  "province":  province,  "City": city,  "branch": branch,  "number": number,  "Bankname":  bankName },                   function  (Result)  {                       if  (result ==  "1")  {                            alert ("Save Success");                            Location.reload ();                      &nbSP;}                        else {                           alert ("Save Failed");                            location.reload ();                       }                  &NBSP});  

Summary: The asynchronous approach is also simpler to implement, of course, this is only one aspect. The most important point is that the value can be returned. We can do the next step based on the values passed in the background, while reducing the server request and reducing the network load.

2. Form mode

(1) Post mode

<1> post way without JS, direct submission

[HTML] View plain copy <form onsubmit= "Layer.load (' Submit in Request ')" action= "/WITHFUNDING/STARTFUNDING/12" method= "POST" > <input type= "hidden" name= CategoryID value= "/>" <input "type=" hidden "name=" Accountmoney "value=" @Vi Ewbag.account "/>

Related Article

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.