Asp.Net4.5 mvc4 页面创建与讲解
2016-03-22 13:42
483 查看
一、Contorl
通过目录结构我们可以看到contorllers类的命名方式
命名规则:前缀+Controller.
在看看contorller中的action方法
每个方法都会通过“return view()”返回一个视图,我们理解为每一个方法名就代表一个视图页面
所以前台访问的路径为:http://域名/contorller前缀/action方法名,如http://http://localhost:40893/Account/Login
二、新建一个页面看看效果
效果:打开http://localhost:40893/Demo/demo,显示:这是我的第一个页面
首先在controllers中创建contorller,命名为DemoController
右击添加-控制器
然后在代码上写上
如果页面需要修饰,我们可以创建一个视图
新建文件夹Demo,然后在Demo下面创建demo.cshtml视图
创建视图的时候首先创建文件夹,名字和contorller前缀一致,具体的页面名称要和action的方法名字一致,否则访问不成功
原文地址:http://www.cnblogs.com/shuang121/p/4018860.html
通过目录结构我们可以看到contorllers类的命名方式
命名规则:前缀+Controller.
在看看contorller中的action方法
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace shuangFirstMvc.Controllers { public class HomeController : Controller { public ActionResult Index() { ViewBag.Message = "修改此模板以快速启动你的 ASP.NET MVC 应用程序。"; return View(); } public ActionResult About() { ViewBag.Message = "你的应用程序说明页。"; return View(); } public ActionResult Contact() { ViewBag.Message = "你的联系方式页。"; return View(); } } }
每个方法都会通过“return view()”返回一个视图,我们理解为每一个方法名就代表一个视图页面
所以前台访问的路径为:http://域名/contorller前缀/action方法名,如http://http://localhost:40893/Account/Login
二、新建一个页面看看效果
效果:打开http://localhost:40893/Demo/demo,显示:这是我的第一个页面
首先在controllers中创建contorller,命名为DemoController
右击添加-控制器
然后在代码上写上
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; namespace shuangFirstMvc.Controllers { public class DemoController : Controller { // // GET: /Demo/ public ActionResult Index() { return View(); } public ActionResult demo() { return Content("这是我的第一个页面"); } } }
如果页面需要修饰,我们可以创建一个视图
新建文件夹Demo,然后在Demo下面创建demo.cshtml视图
@{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>demo</title> </head> <body> <div> 这是我的第一个页面 </div> </body> </html>
创建视图的时候首先创建文件夹,名字和contorller前缀一致,具体的页面名称要和action的方法名字一致,否则访问不成功
原文地址:http://www.cnblogs.com/shuang121/p/4018860.html
相关文章推荐
- WebService中使用Aspose.Cells.dll
- ASP.NET MVC为字段设置多语言显示 [转]
- 【图解ASP.NET MVC运行机制理解-简易版】
- Asp.net TextBox只能输入数字
- [Asp.Net MVC4]验证用户登录实现
- ASP.NET Boilerplate 工作单元
- mvc中Scripts.Render的用法
- 面向切面(AOP)之Spring接口方式 schema配置方式 aspectj注解方式
- Spring Aop实例之AspectJ注解配置
- spring学习笔记(10)@AspectJ研磨分析[3]增强织入顺序实例详解
- spring学习笔记(11)@AspectJ研磨分析[2]切点表达式函数详解
- Server 对象 错误 \'ASP 0178 : 80070005\'
- asp Session 串号的解决方法
- spring学习笔记(10)@AspectJ研磨分析[1]入门、注解基本介绍
- 关于asp.net mvc项目部署到云服务器的一些经验分享
- .NET/ASP.NET 4.5 Bundle组件(捆绑、缩小静态文件)
- NET/ASP.NET Routing路由(深入解析路由系统架构原理)(转载)
- 【ASP.NET MVC路由测试+性能调试工具】
- ASP.NET动态生成GridView的使用
- ASP.NET Web Projects