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 ...
随机推荐
- ORACLE会话数、连接数配置
ORACLE会话数.连接数配置 ORACLE会话数.连接数配置 ORACLE的会话数和连接数参数配置 以sysdba身份登录 sqlplus sys/xxxx as sysdba; 查看最大连接数: ...
- [Compose] 10. Capture Side Effects in a Task
We examine the data structure Task, see some constructors, familiar methods, and finally how it capt ...
- tig install ncursesw
./configure --prefix=/home/xxx/.local/ --with-ncursesw make[xxx$ ldd src/tig linux-vdso.so.1 => ( ...
- PatentTips - Integrated circuit well bias circuitry
1. Field of the Invention This invention relates in general to an integrated circuit and more specif ...
- [Ramda] Curry and Uncurry Functions with Ramda
Most of the functions offered by the ramda library are curried by default. Functions you've created ...
- Android定位开发之百度定位、高德定位、腾讯定位,三足鼎立一起为我所用!
这几天的项目不是非常紧.于是想为未来可能要做的项目做一些技术储备. 下一个项目非常有可能是定位开发,须要用到手机定位功能,于是查了查如今比較流行的第三方定位,最火的基本上就是百度定位>高德定位& ...
- Android 延时执行的几种方法
开启新线程 new Thread(new Runnable(){ public void run(){ Thread.sleep(XXXX); handler.sendMessage(); //告诉主 ...
- 阿里云域名和ip绑定步骤
阿里云域名和ip绑定步骤 一.总结 一句话总结:域名转IP信息存在所在地运营商那,比如电信联通等. 1.给域名添加对应ip的过程叫做什么? 域名解析 2.域名解析中的记录代表什么意思,记录值呢? 记录 ...
- 控制器管理UINavigationController、UINavigationBar
控制器管理 掌握 控制器以及view的多种创建方式 UINavigationController的简单使用:添加\移除子控制器 UINavigationBar内容的设置 控制器的生命周期方法 Segu ...
- 开源库Fab-Transformation简单使用解析
转载请注明出处王亟亟的大牛之路 相似于IPhone的悬浮按钮的操作,仅仅只是是固定的,当然经过自己的改动也能够动.这边仅仅是给伸手党一个福祉,外加加上一些自己的理解.让大家能够拿来就用.看了就懂,废话 ...