MonoRail学习目录

在我们asp.net中,经常有界面代码相同的时候,使用UserControl,在MonoRail中有两种方式来实现页面的重用,
第一种,只重用view
如下:
#parse("home/newslist.vm")
相当于include这个newslist.vm到指定的页面


第二种就是Component
Component创建如下:
1.创建一组件类NewsList.cs

MonoRail学习-Componentusing System;
MonoRail学习-Component
using Castle.MonoRail.Framework;
MonoRail学习-Component
MonoRail学习-Component
namespace MonoRailWeb.components

2.在views目录下创建components目录,在components目录下在创建news,在news目录下创建newslist.vm文件
<table>
<tr><td>$name</td></tr>
</table>
这是组件的界面部分

3.在页面中调用该组件
#component(NewsList)
这样一个组件就创建完成了。
通常,我们会为组件设定一些参数,这样在我们调用组件的时候在设置参数的值。
那么就需要在组件类中得到参数的值,如下:
//得到参数ID的值
string id = Context.ComponentParameters["id"].ToString();

在页面中设置参数的值
#component(NewsListById with "id=1")
若有多个参数,则如下:
#component(NewsListById with "id=1" "name=test")

相关文章:

  • 2022-12-23
  • 2021-12-15
  • 2022-12-23
  • 2021-06-24
  • 2022-12-23
  • 2022-01-28
猜你喜欢
  • 2021-06-22
  • 2021-07-23
  • 2021-09-05
  • 2021-11-26
  • 2021-07-17
  • 2021-06-26
相关资源
相似解决方案