博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Asp.Net4.5 mvc4(二) 页面创建与讲解
阅读量:4509 次
发布时间:2019-06-08

本文共 1582 字,大约阅读时间需要 5 分钟。

一、Contorl

通过目录结构我们可以看到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;}    
demo
这是我的第一个页面

创建视图的时候首先创建文件夹,名字和contorller前缀一致,具体的页面名称要和action的方法名字一致,否则访问不成功

 

转载于:https://www.cnblogs.com/shuang121/p/4018860.html

你可能感兴趣的文章
CF1214D Treasure Island
查看>>
关于分页的一些前后台知识与应用
查看>>
Visual Studio中的快捷键
查看>>
Mac下显示和隐藏“隐藏文件”
查看>>
Chessboard POJ - 2446(最大流 || 匹配)
查看>>
Warning: Cannot modify header information原因及解决方案
查看>>
Python ConfigParser模块
查看>>
程序员的学习和积累
查看>>
.net实现支付宝在线支付
查看>>
centos7 swoole 三步搞定全部
查看>>
noip2014day1题解
查看>>
Excel:一些方法的理解
查看>>
【转】在RHEL上升级Python
查看>>
java:环境变量设置
查看>>
Servlet的学习之Response响应对象(3)
查看>>
基础知识回顾——上下文管理器
查看>>
ARM(RISC)和x86(CISC)的技术差异
查看>>
第3章 对象基础
查看>>
文件压缩与解压缩
查看>>
android 搜索自动匹配关键字并且标红
查看>>