现在的位置: 首页 > 综合 > 正文

NClay框架MVC入门编-文件上传信息绑定

2011年04月19日 ⁄ 综合 ⁄ 共 1602字 ⁄ 字号 评论关闭

      这章节主要讲述如何绑定上传文件信息,组件的出发点就是方便所以在绑定上传文件信息也是一件非常方便的事情;只需要定义相关属性添加个Attribute即可。

文件上传逻辑处理描述

    public interface IUpLoad

    {

        IList<NClay.Web.File> Files

        {

            get;

            set;

        }

    }

    [NClay.MVC.Controller]

    public class LogicHandler

    {

        public void UpLoad(IUpLoad logic)

        {

            //处理文件上传代码

        }

    }

视图成员实现

    [NClay.MVC.Tag("~/UploadFiles.aspx")]

    [NClay.MVC.Post(typeof(IUpLoad))]

    public class UpLoadFiles:IUpLoad

    {

        #region IUpLoad 成员

        [NClay.MVC.Binder.Converter(typeof(NClay.Web.UpLoadConverter))]

        public IList<NClay.Web.File> Files

        { get; set; }

 

        #endregion

    }

组件提供NClay.MVC.Binder.Converter属性用来描述自定义转换功能。

<%@ Page Language="C#" AutoEventWireup="true" Inherits="NClay.Web.FormContext" %>

 

<!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 runat="server">

    <title>无标题页</title>

</head>

<body>

  <form id="form1" enctype="multipart/form-data" method="post" action="UploadFiles.aspx">

  <label>文件1

  <input type="file" name="file" /><br />

  </label>

   <label>文件2

  <input type="file" name="file" /><br />

  </label>

   <label>文件3

  <input type="file" name="file" /><br />

  </label>

   <label>文件4

  <input type="file" name="file" /><br />

  </label>

  <label>

  <input type="submit" name="Submit" value="提交" />

  </label>

</form>

<%

    MVC_UpLoadFile.IUpLoad upload = (MVC_UpLoadFile.IUpLoad)View;

    foreach (NClay.Web.File item in upload.Files)

    {

   

 %>

 文件名称:<%=item.Name %><br/>

 文件类型:<%=item.FileType %><br/>

 文件大小:<%=item.Size %><br/>

 ----------------------------------<br />

 <%} %>

</body>

</html>

在线演示

下载例程

抱歉!评论已关闭.