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>
MVC 自动装配的更多相关文章
- 5.Spring MVC 自动装配问题
一.使用@controller注解,实际上也是在IOC容器中配置了,它的id是类的首字母小写 一.使用@controller注解,实际上也是在IOC容器中配置了,它的id是类的首字母小写 1.如果不使 ...
- Spring Boot 自动装配(二)
目录 目录 前言 1.起源 2.Spring Boot 自动装配实现 2.1.@EnableAutoConfiguration 实现 2.1.1. 获取默认包扫描路径 2.1.2.获取自动装配的组件 ...
- ASP.NET WebForm Form表单如何实现MVC那种“自动装配”效果呢?
我们知道ASP.NET MVC有个强大的地方就是Form表单提交到action的时候,可以直接将Form的参数直接装配到action的参数实体对象中 比如 action方法 Register(User ...
- 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 ...
- Asp.Net MVC之 自动装配、动态路径(链接)等
一.Model层 using System; using System.Collections.Generic; using System.Linq; using System.Web; namesp ...
- MVC参数自动装配
在拿到一个类型的所有属性以及字段的描述信息后,就可以通过循环的方式,根据这些数据成员的名字去QueryString,Form,Session,Cookie读取所需的数据了. 就是遍历参数,然后用反射遍 ...
- spring自动装配
spring提供了自动装配(autowiring)和自动检测(autodiscovery)用来减少XML的配置数量. 自动装配bean属性 byName——把与Bean的属性具有相同名字(或ID)的其 ...
- Spring 自动装配及自动注册的相关配置
Spring支持好几种自动装配(Autowiring)的方式,以及自动扫描并注册Bean的配置(在beans.xml中配置). 下文我们进行一个小结. 1. <context: annotati ...
- SpringMvc自动装配@Controller无效
1.问题原因:SpringMvc驱动器没有扫描该Controller层 虽然配置了 <!-- 启用spring mvc 注解 --> <context:annotation-conf ...
随机推荐
- VNC不同用户 Oracle
VNC登录用户缺省是root,但在安装oracle时必须用oracle用户的身份登录,下面我们就以oracle为例说明如何配置VNC,从而可以使用不同的用户登录到主机.步骤描述如下: 步骤一:修 ...
- [Django] The admin interface
Now let's see how to access admin interface. 1. Create a super user which can access admin interface ...
- 数据预处理(normalize、scale)
matlab 工具函数(三)-- normalize(归一化数据) 注:待处理的数据 X∈Rd×N,N 表示样本的个数,d 则是单个样本的维度: 1. 去均值(remove DC) X = bsxfu ...
- erlang与c之间的连接
http://blog.chinaunix.net/uid-22566367-id-382012.html erlang与c之间的连接参考资料:网络资料作者:Sunny 在Programming ...
- 使用Ant包装时,包javax.servlet.http有没有搞错
明确,出现此错误的原因是缺乏相应的jar包.详细原因因为servlet和JSP不是Java平台JavaSE(标准版)的一部分.而是Java EE(企业版)的一部分,因此,必须告知编译器servlet的 ...
- 【poj2406】next数组求循环节
传送门 题目分析 本题主要考察kmp中next数组在求循环时的运用: 字符串是循环的: len % (len - next[len]) == 0 字符串循环次数: len / (len - next[ ...
- TensorFlow 学习(六) —— TensorFlow 与 numpy 的交互
1. 将 numpy 下的多维数组(ndarray)转化为 tensor a = np.zeros((3, 3)) ta = tf.convert_to_tensor(a) with tf.Sessi ...
- 浅谈Linux下各种压缩 解压命令和压缩比率对比
Linux下压缩.解压命令五花八门,不像在windows下一个winrar打遍天下无敌手,清一色的.rar .zip格式. 比如,Linux下常用的tar tar.gz tar.bz2 .Z等等不一而 ...
- 在WSL中安装和运行Docker CE
安装环境 Windows 10 64bit 专业版 1809 WSL安装ubuntu 18.04 LTS DOCKER安装 安装过程没有什么问题,安装docker的网站说明进行安装https://do ...
- VS 2017正式版
Visual Studio 2017正式版发布全纪录 又是一年发布季,微软借着Visual Studio品牌20周年之际,于美国太平洋时间2017年3月7日9点召开发布会议,宣布正式发布新一代开发利器 ...