Some methods of the value that MVC takes from the foreground page to pass from the background page.

Source: Internet
Author: User

Some methods of the value that MVC takes from the foreground page to pass from the background page .

<1> Front Page Index view

Note: The name value of the user name form is txtname

The name value of the password form is Txtpassword

1 <HTML>2 <Head>3     <Metaname= "Viewport"content= "Width=device-width" />4     <title>Test</title>5 </Head>6 <Body>7     <formAction= "/home/test"Method= "POST">8         <Div>9             <label>User name</label><inputtype= "text"name= "Txtname" />Ten             <label>Password</label><inputtype= "text"name= "Txtpassword" /> One         </Div> A         <inputtype= "Submit"value= "Submit" /> -     </form> - </Body> the </HTML>

<2> background page, Home controller (for testing, the action of the From form in the View page is set to action= "/home/test", action= "/home/test2" action= "/home/test3", respectively action= "/home/test4")

1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingsystem.web;5 usingSYSTEM.WEB.MVC;6 7 namespacemvcapplication1.controllers8 {9      Public classHomecontroller:controllerTen     { One         // A         //GET:/home/ -  -          Publicactionresult Index () the         { -             returnView (); -         } -  +         /// <summary> -         ///MVC first method of value +         /// </summary> A         /// <returns></returns> at          Publicactionresult Test () -         { -             stringUserName = request["txtname"];//at this time request["Txtname"]=abc -             stringPassword = request["Password"];//at this time request["password"]=123 -  -             returnContent ("OK"+ UserName +password); in         } -         /// <summary> to         ///The second way of taking value +         /// </summary> -         /// <param name= "F" ></param> the         /// <returns></returns> *          PublicActionResult Test2 (formcollection f)//FormCollection is a collection of forms in MVC that can also be used to receive forms submitted by the foreground, and the forms submitted by the foreground are all encapsulated in this object. $         {Panax Notoginseng             stringUserName = f["txtname"];//at this time f["Txtname"]=abc -             stringPassword = f["Txtpassword"];//at this time f["Txtpassword"]=123 the  +             returnContent ("OK"+ UserName +password); A         } the         /// <summary> +         ///The Third way of taking value -         /// </summary> $         /// <param name= "txtname" ></param> $         /// <param name= "Txtpassword" ></param> -         /// <returns></returns> -          PublicActionResult Test3 (stringTxtname,stringTxtpassword)//Note that the name of this parameter must be the same as the foreground page control's name value the         { -             returnContent ("OK"+ Txtname +txtpassword);Wuyi  the             //at this time textname=abc -             //at this time txtpassword=123 Wu         } -  About         /// <summary> $         ///the Fourth Way -         /// </summary> -         /// <param name= "txtname" ></param> -         /// <param name= "Txtpassword" ></param> A         /// <param name= "p" ></param> +         /// <returns></returns> the          PublicActionResult Test4 (stringTxtname,stringTxtpassword, Paraclass P)//if the attribute inside the Paraclass class is consistent with the name value of the foreground page control, its object properties are automatically assigned -         { $             returnContent ("OK"+ txtname + txtpassword + p.txtname +P.txtpassword); the  the             //at this time textname=abc the             //at this time txtpassword=123 the  -             //at this time p.txtname=abc in             //at this time p.txtpassword=123 the         } the  About  the          Public classParaclass the         { the              Public stringtxtname {Get;Set; }//at this time textname=abc +              Public stringTxtpassword {Get;Set; }//at this time txtpassword=123 -         } the       Bayi     } the}


Some methods of the value that MVC takes from the foreground page to pass from the background page.

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.