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>

  • 相关阅读:
    C#秘密武器之表达式树
    C#秘密武器之特性
    [转]拷贝构造函数详解
    [转]STL 容器一些底层机制
    C++ Qt多线程 TcpSocket服务器实例
    QByteArray储存二进制数据(包括结构体,自定义QT对象)
    [转]浅谈 C++ 中的 new/delete 和 new[]/delete[]
    [转]QList内存释放
    Subscribe的第四个参数用法
    ROS多线程订阅消息
  • 原文地址:https://www.cnblogs.com/dxmfans/p/9434751.html
Copyright © 2011-2022 走看看