MVC form submission Notation 1

Source: Internet
Author: User

To start with MVC, which is very different from the previous ASPX page, let's look at how the MVC form is submitted.

Now let's take a look at the simplest example of how MVC submits the form (in this case, our focus is how to submit the form, so it doesn't involve any business logic)

Model:

usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;namespacemvcapplication2.models{ Public classStudent { Public intId {Get;Set; }  Public stringName {Get;Set; } }}

View:

@model mvcapplication2.models.student@{viewbag.title="Index";}@using (Html.BeginForm ("Index","Home") {@Html. Label ("Label1") @Html. Textboxfor (M=m.name)<input type="Submit"Value="Submit 1"/>}

Controller:

usingMvcapplication2.models;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingsystem.web;usingSYSTEM.WEB.MVC;namespacemvcapplication2.controllers{ Public classHomecontroller:controller {//the @using on the page (Html.BeginForm ("Index", "Home") indicates that our form is Home/index         PublicActionResult Index () {returnView (); }        //marking as HttpPost indicates that this method is called when "Commit 1" is on the point interface. //that is achieved, from the interface to the background of a process. [HttpPost] Publicactionresult Index (Student Student) {returnView (); }    }}

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.