【asp.net】MVC模板中各个文件的功能和作用

一、App_Data :存放数据库或xml文件。

二、App_Start: 配置文件夹,

1、BundleConfig.cs (打包器,打包专用的配置文件)

2、FilterConfig.cs(过滤器配置)

书写过滤规则              如异常过滤,权限过滤等

3、RouteConfig.cs (路由配置)

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace HPIT.RentHouse.Admin
{
    public class RouteConfig
    {
        public static void RegisterRoutes(RouteCollection routes)
        {
            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

            routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = 
  UrlParameter.Optional } 
 //controller = "Home", action = "Index",配置为默认打开【views】中【home】文件夹中的【index.cshtml】首页文件.
            );
        }
    }
}

三、Content(放CSS样式文件或图片)

主要存放 CSS文件。

四、Controllers(放控制器文件,MVC中的C)
1、存放与Views中cshtml文件对应.cs代码文件。

2、在Controllers右键,添加控制器后(如:userControllers,注意,起名后面一定要带Controllers),系统会自动在Views中添加一个user的文件夹。

3、在Index点右键可以【添加视图】,添加后,在Views中增加一个index.cshtml文件。

五、fonts(图标字体文件)
主要存放字体文件。

六、Models(放ViewsModels,MVC中的M)
存放实体对象,数据结构

七、Scripts(存放js和JQ等脚本文件)

八、views(存放前台html页面的文件夹,,MVC中的V)
1、shared(存放共享母板页文件夹)
2、_Layout.cshtml(系统默认通用母板文件)
一般用于存放所有视图页面公用的js、css等载入,这样,就不需要在每个cshtml页面重复载入了。

九、Web.config(配置文件,包括:数据库连接字符串等)

十、Global.asax:全局应用程序

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;

namespace HPIT.RentHouse.Admin
{
    public class MvcApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            //此处顺序不能改
        
            AreaRegistration.RegisterAllAreas();
            //
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            //过滤器
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            //路由
            BundleConfig.RegisterBundles(BundleTable.Bundles);
            //打包器
        }
    }
}

总结图


 

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值