首页 新闻 会员 周边

关于webform模板引擎

0
悬赏园豆:100 [已关闭问题] 关闭于 2014-08-28 09:36
<%@ Page
    Language           = "C#"
    AutoEventWireup    = "false"
    Inherits           = "Moon.Web.MoonPage<string>
    ValidateRequest    = "false"
    EnableSessionState = "false"
%>

<!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><%=this.Model%></title>

        <meta http-equiv="content-type" content="text/html; charset=utf-8" />
        <meta http-equiv="CACHE-CONTROL" content="NO-CACHE" />
        <meta http-equiv="PRAGMA" content="NO-CACHE" />

        <link href="Moon.WebTest.css" type="text/css" rel="stylesheet" />
        
    </head>
    <body>
         <%=this.Model%><br/>
    </body>
</html>

上面是页面.对应于我的一个库(另外一个dll)中的类,定义格式如下.

using System;
using System.Web.UI;

namespace Moon.Web
{
    public class MoonPage<T> :Page  
    {    
        /// <summary>
        /// 用于页面呈现时所需的数据实体对象
        /// </summary>
        public T Model 
        {
            get; 
            set;
        }
        public  void SetModel(T model)
        {
            this.Model =model;
        }
    }
}

 

问题是:我不能通过以下这个方法,将使用对应的aspx

 

public static    string RenderAspx<T>(HttpContext context,string virtualPath,T model  )
        {
            MoonPage<T> handler = null;
            try {
                var a = BuildManager.CreateInstanceFromVirtualPath(virtualPath, typeof(MoonPage<T>));
                handler = a as MoonPage<T>;
            } catch (Exception ex) {
                var a = ex;
                throw new Exception(ex.Message + ex.GetType().ToString());
            }
            if (handler == null) {
                throw new InvalidOperationException(string.Format("指定的路径 {0} 不是一个有效的页面。", virtualPath));
            }
            handler.Model = model;
            string html = null;
            StringWriter sw = new StringWriter();
            context.Server.Execute(handler, sw, false);
            html = sw.ToString();
            return html;
        }

报错内容:

未能加载类型“Moon.Web.MoonPage<string>”。System.Web.HttpParseException

 

注:如果给这个aspx文件加上对应的一个.cs就可以正常使用了啦.

如:

namespace Moon.WebTest
{
    public class WebForm1 : Moon.Web.MoonPage<string>
    {    
         
    }
}

然后页面上对应类改为

 Inherits           = "Moon.WebTest.WebForm1"

 

这样就OK了,问:我是否能够单独要aspx文件?

迅捷网络[来送福利]的主页 迅捷网络[来送福利] | 小虾三级 | 园豆:576
提问于:2014-08-24 20:50
< >
分享
所有回答(2)
0

原生的.net是可以不用cs只有aspx的,但是mono里面各种坑。

realanan | 园豆:232 (菜鸟二级) | 2014-08-25 09:08

我今天就给你看看

支持(0) 反对(0) 迅捷网络[来送福利] | 园豆:576 (小虾三级) | 2014-08-25 09:14
0

web.config

  <pages pageBaseType="Moon.Web.MoonPage">

西安-DB | 园豆:4 (初学一级) | 2014-08-25 09:19
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册