Ejemplo n.º 1
0
        public void AddStringTemplate()
        {
            mHost.AddTemplate("/test", "@Raw(DataContext.EMail)");
            string value = mHost.Parse("/test", new { EMail = "*****@*****.**" });

            Console.Write(value);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            ITemplateHost mHost = Razor.CreateHost();

            mHost.LoadTemplateFiles();

            mHost.AddTemplate("/master", "<h1>主页面</h1>@RenderBody()");

            mHost.AddTemplate("/user", "<div><h3>用户信息</h3><p>email:@DataContext.EMail</p><p>name:@DataContext.Name</p></div>");

            mHost.AddTemplate("/users", "<div class=\"user-list\"><h2>用户列表</h2>@Each(\"/user\",Model.Items)<div>");


            string value = mHost.Parse("/user", new User {
                EMail = "*****@*****.**", Name = "henry"
            });

            Console.WriteLine(value);


            value = mHost.Parse("/users", new { Items = new User[] {
                                                    new User {
                                                        EMail = "*****@*****.**", Name = "henry"
                                                    },
                                                    new User {
                                                        EMail = "*****@*****.**", Name = "henry1"
                                                    }
                                                } });
            Console.WriteLine(value);

            value = mHost.Parse("/users", "/master", new
            {
                Items = new User[] {
                    new User {
                        EMail = "*****@*****.**", Name = "henry"
                    },
                    new User {
                        EMail = "*****@*****.**", Name = "henry1"
                    }
                }
            });
            Console.WriteLine(value);


            mHost.AddTemplate("/test", "@Raw(DataContext.EMail)");
            value = mHost.Parse("/test", new { EMail = "[email protected]<a>" });
            Console.Write(value);


            value = mHost.Parse("/views/raw", null);
            Console.Write(value);

            value = mHost.Parse("/views/index", "/views/master",
                                new { EMail = "*****@*****.**", Name = "henryfan" });
            Console.Write(value);

            value = mHost.Parse("/views/foreachSection", new { Items = new User[] { new User(), new User() } });
            Console.Write(value);

            Console.Read();
        }