ASP.NET开源MVC框架Vici MVC(二)Controllers和templates基础

ASP.NET开源MVC框架Vici MVC 最大的特点是支持ASP.NET2.0  iis不需要额外的设置

官方实例下载地址http://viciproject.com/wiki/Projects/Mvc/UserGuide/Routing

 

Vici的Controllers和templates和ASP.NET mvc还要点不太一样

首先是Controllers

11

index 的内容如下

 public class index : Controller
    {

        public void Run()
        {
            ViewData["msg"] = "helloword";
        }

        [View("home")]
        public void home()
        {
            ViewData["msg2"] = "helloword2";
           // ChangeLayout("");
            //RenderView("");
         

        }

    }

1注意index继承Controller

2注意index.cs 只要放在Controllers下面就行了,至于是放在Controllers/a 还是Controllers/B 没有关系 只要 类名为index且继承了Controller就行

Run() 方法为 只访问Controller时执行的 开始我以为和构造函数擦不多 后来发现不是 如果访问index/home.aspx就直接执行home()了

然后是模板

22

Vici的模板有2个限制

1文件的后缀只能是  .htm

2必须有一个模板的模板系统默认是master.htm

模板的要注意一个地方  {{@VIEW}} ,这个标记是占位的 其他模板的内容(其他模板body里的内容)会出现在这个地方

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
模板页
{{@VIEW}}
</body>
</html>

悲伤理解的不深刻就只能这样了

posted @ 2011-04-09 22:57  互联网Fans  阅读(587)  评论(0编辑  收藏  举报