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 ...
随机推荐
- HttpServletRequest方法
HttpServletRequest HttpServletRequest对象代表客户端的请求,当客户端通过HTTP协议访问服务器时,HTTP请求头中的所有信息都封装在这个对象中,开发人员通过这个对象 ...
- [tmux] Customize tmux with tmux.conf
You can modify tmux's behavior with your tmux configuration file, .tmux.conf. You can use your tmux ...
- 【t034】Matrix67的派对
Time Limit: 1 second Memory Limit: 1 MB [问题描述] Matrix67发现身高接近的人似乎更合得来.Matrix67举办的派对共有N(1<=N<=1 ...
- [redis] redis配置文件redis.conf的详细说明
# Redis 配置文件 # 当配置中需要配置内存大小时,可以使用 1k, 5GB, 4M 等类似的格式,其转换方式如下(不区分大小写) # # 1k => bytes # 1kb => ...
- noip刷题记录 20170818
天天爱跑步 lca + 树上差分 #include<iostream> #include<cstdio> #include<cstdlib> #include< ...
- hibernate annotation 相关主键生成策略
Hibernate 默认的全面支持 13 物种生成策略 : 1. increment 2. identity 3. sequence 4. hilo 5. seqhilo 6. uuid 7. uu ...
- 利用navicat写mysql的存储过程
最近项目经理让我给新的活动的预留一个插入红包和查看详情的sql,方便在项目出问题的做一些紧急操作,我想了下这里面还涉及到挺多逻辑和挺多表的一句句查也不方便啊,干脆写到存储过程里,于是开始在navica ...
- vue 一些webpack的配置详解
最近一直在忙着做项目 本来想养成一个经常跟新博客的习惯 , 但是实在是太难了 , 每天加班到10点多 .8点能下班都是最好的了 , 小公司真不好待呀 分享一下最近半年的vue心得吧 我的项目是在他的基 ...
- 世界卫生组织(WHO)发出最新警告:埃博拉疫情应急响应
10月14r日.世界卫生组织(WHO)发出警告:在未来两个月内,西非国家将面对"could face up to 10 thousand new Ebola cases a week wit ...
- 【从翻译mos文章】采用高速全扫描索引(index ffs) 为了避免全表扫描
采用高速全扫描索引(index ffs) 为了避免全表扫描 参考原始: Index Fast Full Scan Usage To Avoid Full Table Scans (Doc ID 701 ...