The form submission and the controller accept the data submitted by the form in ASP.

Source: Internet
Author: User

How the form is submitted and accepted in the controller in MVC

1.cshtml page form submission


2. Controller processing form submission Data 4 ways
Method 1: Use traditional request requests to fetch values
[HttpPost]
Public ActionResult Addnews ()
{
String a=request["Text1"];
String b=request["Text2"];
}
method 2:action parameter name corresponds to table cell name value one by one
[HttpPost]
Public ActionResult addnews (string text1,string text2)
{
String A=text1;
String b=text2;
}
Method 3: Read from the MVC encapsulated formcollection container
[HttpPost]
Public ActionResult addnews (formcollection form)
{
String a=form["Text1"];
String b=form["Text2"];
}
Method 4: Use the entity as the action parameter to pass in, provided that the submitted form element name corresponds to the entity attribute name one by one
[HttpPost]
Public ActionResult addnews (Usermodel user)
{
String A=user.text1;
String b=user.text2;
}

The form submission and the controller accept the data submitted by the form in ASP.

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.