• Asp.net mvc4 快速入门之构建表单


    1、asp.net mvc4  Index.cshtml页面上构建表单form的方式

    @{
        ViewBag.Title = "Index";
        Layout = "~/Views/Shared/_Layout.cshtml";
    }
    @model MvcFastEntry.Models.Student
    
    @*构建form表单方式1*@
    @using(Html.BeginForm("Index","BiaoDan",FormMethod.Post))
    {
       <div> @Html.LabelFor(m=>m.userName)</div>
       <div> @Html.TextBoxFor(m => m.userName)</div>
       <div> <input type="submit" value="提交" /></div>
    }
    
    @*构建form表单方式2*@
    <div>
        @{Html.BeginForm("Index", "BiaoDan", FormMethod.Post);}
        <div> @Html.LabelFor(m=>m.userName)</div>
       <div> @Html.TextBoxFor(m => m.userName)</div>
       <div> <input type="submit" value="提交" /></div>
    @{Html.EndForm();}
    </div>

    说明:(1)、@model MvcFastEntry.Models.Student 引用Student.cs实体类

    Student.cs类代码如下:

    using System;
    using System.Collections.Generic;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Web;
    
    namespace MvcFastEntry.Models
    {
        public class Student
        {
            public int id { get; set; }
            [Display(Name="姓名")]
            public string userName { get; set; }
            public string userClass { get; set; }
        }
    }
    View Code

    (2)、 @{Html.BeginForm("Index", "BiaoDan", FormMethod.Post);}  其中“BiaoDan”是控制器的名称,“Index”是action方法的名称

    BiaoDan控制器代码如下:

     public class BiaoDanController : Controller
        {
            //
            // GET: /BiaoDan/
            //该示例展示怎么构建form表单
            public ActionResult Index()
            {
                Student student = new Student()
                {
                    id = 1,
                    userClass = "二班",
                    userName = "小明"
                };
                return View(student);
            }
    }
    }
  • 相关阅读:
    【博弈】UVA10561 Treblecross
    2021牛客暑期多校训练营2 部分题解
    2021牛客暑期多校训练营1 部分题解
    变量
    第六次作业
    第五次作业
    第四次作业
    第三次作业
    第二次作业
    c#下载网页源码的两种方法
  • 原文地址:https://www.cnblogs.com/net064/p/8876633.html
Copyright © 2020-2023  润新知