//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>

MVC 自动装配的更多相关文章

  1. 5.Spring MVC 自动装配问题

    一.使用@controller注解,实际上也是在IOC容器中配置了,它的id是类的首字母小写 一.使用@controller注解,实际上也是在IOC容器中配置了,它的id是类的首字母小写 1.如果不使 ...

  2. Spring Boot 自动装配(二)

    目录 目录 前言 1.起源 2.Spring Boot 自动装配实现 2.1.@EnableAutoConfiguration 实现 2.1.1. 获取默认包扫描路径 2.1.2.获取自动装配的组件 ...

  3. ASP.NET WebForm Form表单如何实现MVC那种“自动装配”效果呢?

    我们知道ASP.NET MVC有个强大的地方就是Form表单提交到action的时候,可以直接将Form的参数直接装配到action的参数实体对象中 比如 action方法 Register(User ...

  4. IDEA02 利用Maven创建Web项目、为Web应用添加Spring框架支持、bean的创建于获取、利用注解配置Bean、自动装配Bean、MVC配置

    1 环境版本说明 Jdk : 1.8 Maven : 3.5 IDEA : 专业版 2017.2 2 环境准备 2.1 Maven安装及其配置 2.2 Tomcat安装及其配置 3 详细步骤 3.1 ...

  5. Asp.Net MVC之 自动装配、动态路径(链接)等

    一.Model层 using System; using System.Collections.Generic; using System.Linq; using System.Web; namesp ...

  6. MVC参数自动装配

    在拿到一个类型的所有属性以及字段的描述信息后,就可以通过循环的方式,根据这些数据成员的名字去QueryString,Form,Session,Cookie读取所需的数据了. 就是遍历参数,然后用反射遍 ...

  7. spring自动装配

    spring提供了自动装配(autowiring)和自动检测(autodiscovery)用来减少XML的配置数量. 自动装配bean属性 byName——把与Bean的属性具有相同名字(或ID)的其 ...

  8. Spring 自动装配及自动注册的相关配置

    Spring支持好几种自动装配(Autowiring)的方式,以及自动扫描并注册Bean的配置(在beans.xml中配置). 下文我们进行一个小结. 1. <context: annotati ...

  9. SpringMvc自动装配@Controller无效

    1.问题原因:SpringMvc驱动器没有扫描该Controller层 虽然配置了 <!-- 启用spring mvc 注解 --> <context:annotation-conf ...

随机推荐

  1. android Navigator的高度计算和推断是否显示

    进入互联网行业几天了, 从手机行业转到互联网行业也在慢慢的适应: IDE工具的使用(之前一直在Ubuntu 命令行进行开发). 版本号管理工具,代码架构等等这些都须要又一次适应. 好在本人另一些底子, ...

  2. AngularJS之基本指令(init、repeat)

    <h3>ng-init初始化变量</h3> <div ng-init="name='aurora';age='18'"> <p ng-bi ...

  3. [Compose] Isomorphisms and round trip data transformations

    What is Isomorphisms?We have a value x, then apply function 'to' and 'from' to value 'x', the result ...

  4. Fragment嵌套Fragment时遇到的那些坑

    由于项目要改成MVP模式,自然会用到了Fragment,有时候可能会需要一个Fragment里面嵌套多个Fragment,并且add完成后需要立即刷新子Fragment的View,那么这个时候就会抛出 ...

  5. 代码包结构分析工具JDepend的使用方法

    JDepend可以对Java软件包结构质量进行分析,已经有很多文章介绍其基本作用和能够计算的指标了,这里我就不详细总结,感兴趣的朋友可以参看如:http://blog.csdn.net/hantian ...

  6. [Ramda] Get a List of Unique Values From Nested Arrays with Ramda (flatMap --> Chain)

    In this lesson, we'll grab arrays of values from other arrays, resulting in a nested array. From the ...

  7. head first c 笔记&lt;3&gt; 之做一件事并把它做好

    1.标准输入.输出与重定向 scanf()和printf()分别为标准输入输出.默认的会从键盘得到数据,在显示器输出数据,是fscanf()和fprintf()函数的特例. 我们也能够用重定向来改变默 ...

  8. html5--1.12表格详解

    html5--1.12表格详解 一.总结 一句话总结: 二.详解 1.表格构成三个基本要素 table:表格的范围,外框:用来定义表格,表格的其他元素包含在table标签里面: tr: 表格的行: t ...

  9. DDoS ATTACK PROCESSING APPARATUS AND METHOD IN OPENFLOW SWITCH

    An OpenFlow switch in an OpenFlow environment includes an attack determination module to collect sta ...

  10. 今天犯了个小错误:_dataArray.count>1 和_dataArray.count>0搞混淆了

    _dataArray.count>1 和_dataArray.count>0搞混淆了:当数据为一条时,条件不成立.应该_dataArray.count>=1  或者>0   ( ...