freemarker.net模板引擎【ASP.NET MVC】

       Freemmarker模板引擎,来自Java的JSP。.NET上进行了移植,形成Freemarker.Net模板引擎。

关于Freemarker.Net的详细介绍,请参考:http://freemarkernet.codeplex.com/documentation

      用法:

     首先引用一下类库:

  2、在全局配置文件Global.asax.cs中,配置如下:

protected void Application_Start() {
            AreaRegistration.RegisterAllAreas();

            //ViewEngines.Engines.Clear();
            *ViewEngines.Engines.Add(new FreemarkerViewEngine(this.Server.MapPath("~/")));*

            RegisterGlobalFilters(GlobalFilters.Filters);
            RegisterRoutes(RouteTable.Routes);
        }

3、创建控制器

    public class HomeController : Controller {
        public ActionResult Index() {
            ViewData["Message"] = "Welcome to ASP.NET MVC!";

            return View();
        }

        public ActionResult About() {
            return View();
        }
    }
<!DOCTYPE html>
<html>
<head>
    <title>Home Page</title>
    <link href="${url.Content("~/Content/Site.css")}" rel="stylesheet" type="text/css" />
    <script src="${url.Content("~/Scripts/jquery-1.5.1.min.js")}" type="text/javascript"></script>
</head>
<body>
    <div class="page">
        <div id="header">
            <div id="title">
                <h1>FreeMarker MVC Application</h1>
            </div>
            <div id="logindisplay">
		<#if request.IsAuthenticated>
			Welcome <strong>${http.User.Identity.Name}</strong>!
			[ ${html.ActionLink("Log Off", "LogOff", "Account")} ]
		<#else>
			[ ${html.ActionLink("Log On", "LogOn", "Account")} ]
		</#if>
            </div> 
            <div id="menucontainer">
                <ul id="menu">
                    <li>${html.ActionLink("Home", "Index", "Home")}</li>
                    <li>${html.ActionLink("About", "About", "Home")}</li>
                    <li>${html.ActionLink("Person", "Index", "Person")}</li>
                </ul>
            </div>
        </div>
        <div id="main">
            <h2>${controller.ViewData.Message}</h2>
            <p>
            	To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
            </p>
            <div id="footer">
            </div>
        </div>
    </div>
</body>
</html>

最后,运行ASP.NET程序。

无意中,做了一次社区的搬运工,感兴趣的朋友,可以试用下。

转载于:https://my.oschina.net/lichaoqiang/blog/868647

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值