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>

  • 相关阅读:
    常用的网站cms内容管理系统推荐
    PageAdmin网站内容管理系统出现403错误的解决方法
    使用PageAdmin网站内容管理系统做网站的好处
    网站建设步骤及常用建站系统分享
    企业网站建设如何选择建站公司
    如何采用PageAdmin自助建站系统来进行企业网站建设
    站群系统-站群软件系统推荐
    js计算之递归
    算法之插入排序
    javaScript设计模式之常用工厂模式
  • 原文地址:https://www.cnblogs.com/dxmfans/p/9434751.html
Copyright © 2011-2022 走看看