zoukankan      html  css  js  c++  java
  • MVC 自动装配

    //HelloController.cs

    using FirstMVC.Models;

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;


    namespace FirstMVC.Controllers
    {
        public class HelloController : Controller
        {
            //
            // GET: /Hello/


            public ActionResult Index()
            {
                return View();
            }


            public ActionResult Say()
            {
                return Content("abc");
            }


            public ActionResult RedirectTest()
            {
                return Redirect(Url.Action("Index","Hello"));
            }


            public ActionResult JsonTest()
            {
                Person p = new Person()
                {
                    Age = 10,
                    QQ = "123"
                };
                return Json(p, JsonRequestBehavior.AllowGet);
            }


            public ActionResult Add()
            {
                ViewBag.id = Request["id"];
                return View();
            }
            [HttpPost]
            public ActionResult Add(int id)//自动装配
            {
                ViewBag.id2 = id;
                return View();
            }


            public ActionResult AddPerson()
            {
                return View();
            }
            [HttpPost]
            public ActionResult AddPerson(Person p)//自动装配
            {
                ViewData.Model = p;
                return View("AddPerson1");
            }
            


        }

    }


    //AddPerson.cshtml

    @model FirstMVC.Models.Person
    @{
        Layout = null;
    }


    <!DOCTYPE html>


    <html>
    <head>
        <meta name="viewport" content="width=device-width" />
        <title>AddPerson</title>
    </head>
    <body>
        <div>
            @using (Html.BeginForm("AddPerson", "Hello", FormMethod.Post))
            {
                <span>Age:</span>@Html.TextBoxFor(p => p.Age);<br />
                                 
                <span>QQ:</span>@Html.TextBoxFor(p => p.QQ); <br />
                                
                <input type="submit" name="name" value=" submit" />         
            }
        </div>
    </body>
    </html>

  • 相关阅读:
    jQuery 源码解析(二十四) DOM操作模块 包裹元素 详解
    jQuery 源码解析(二十三) DOM操作模块 替换元素 详解
    jQuery 源码解析(二十二) DOM操作模块 复制元素 详解
    jQuery 源码分析(二十一) DOM操作模块 删除元素 详解
    jQuery 源码分析(二十) DOM操作模块 插入元素 详解
    jQuery 源码分析(十九) DOM遍历模块详解
    python 简单工厂模式
    python 爬虫-协程 采集博客园
    vue 自定义image组件
    微信小程序 image组件坑
  • 原文地址:https://www.cnblogs.com/dxmfans/p/9434751.html
Copyright © 2011-2022 走看看