• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Asp.netmvc+Ajax+Extjs+NHibernate系列之MVC

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

概述

Asp.net mvc 是微软的开源项目,http://www.asp.net/mvc此处有开源地址,大家可以去下载源代码。不用去想,MVC即,modelviewcontroller。而微软提供的框架,使我们不用关心框架本身,而只需要去实现自己的部分,去构建属于自己的网站即可。

详解

Model层,所有项目中所有实体在该层表示,例如数据库中的对象等。前面提到的SystemConfigMVCDemo.Entity层中的实体便可以使用。

简短实现代码:


 [Serializable]
    
public class SystemConfig : BaseObject<decimal>
    {
        
#region 成员

        
private string _FieldName;
        
private string _FieldValue;
        
private int _FieldGroup;
        
private string _Creator;
        
private DateTime? _CreateDT;
        
private string _Updator;
        
private DateTime? _UpdateDT;

        
#endregion

        
#region 构造函数

        
public SystemConfig()
        { }

        
public SystemConfig(string FieldName, string FieldValue, int FieldGroup, string Creator, DateTime CreateDT, string Updator, DateTime UpdateDT)
        {
            
this._FieldName = FieldName;
            
this._FieldValue = FieldValue;
            
this._FieldGroup = FieldGroup;
            
this._Creator = Creator;
            
this._CreateDT = CreateDT;
            
this._Updator = Updator;
            
this._UpdateDT = UpdateDT;
        }

        
#endregion

        
#region 属性

        
/// <summary>
        
/// 获取与设置字段名称
        
/// </summary>
        public virtual string FieldName
        {
            
get { return _FieldName; }
            
set { _FieldName = value; }
        }
        
#endregion
    }

 

 

 View 层,即*.aspx ,网页,你在设计是,只关注把页面样式调整好,是属于客户端显示的部分。所能看得到的部分。

简短代码如下:


<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<SystemConfigMVCDemo.Entity.SystemConfig>>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    
<h2>
        列表
</h2>
    
<link href="http://www.cnblogs.com/ext/resources/css/ext-all.css" rel="stylesheet" type="text/css" />

    
<script src="http://www.cnblogs.com/ext/adapter/ext/ext-base.js" type="text/javascript"></script>
    
<script src="http://www.cnblogs.com/ext/ext-all.js" type="text/javascript"></script>

    
<script src="http://www.cnblogs.com/Content/SystemConfig/SystemConfigAjax.js" type="text/javascript"></script>

    
<script src="http://www.cnblogs.com/Content/SystemConfig/AjaxFrame.js" type="text/javascript"></script>

    
<script src="http://www.cnblogs.com/Content/SystemConfig/SystemConfigForm.js" type="text/javascript"></script>
    
<table>
        
<tr>
            
<th>
            
</th>
            
<th>
                FieldName
            
</th>
            
<th>
                FieldValue
            
</th>
            
<th>
                FieldGroup
            
</th>
            
<th>
                Creator
            
</th>
            
<th>
                CreateDT
            
</th>
            
<th>
                Updator
            
</th>
            
<th>
                UpdateDT
            
</th>
            
<th>
                PkId
            
</th>
            
<th>
                IsChanged
            
</th>
            
<th>
                IsDeleted
            
</th>
        
</tr>
        
<% foreach (var item in Model)
           { 
%>
        
<tr ondblclick="ShowForm(<%=item.PkId %>)">
            
<td>
                
<%= Html.ActionLink("Edit""Edit"new { id = item.PkId,flag = "Edit" })%>|
                
<%= Html.ActionLink("Details""Details"new { id = item.PkId })%>|
                
<%= Html.ActionLink("Delete""Delete"new { id=item.PkId})%>
            
</td>
            
<td>
                
<%= Html.Encode(item.FieldName) %>
            
</td>
            
<td>
                
<%= Html.Encode(item.FieldValue) %>
            
</td>
            
<td>
                
<%= Html.Encode(item.FieldGroup) %>
            
</td>
            
<td>
                
<%= Html.Encode(item.Creator) %>
            
</td>
            
<td>
                
<%= Html.Encode(String.Format("{0:g}", item.CreateDT)) %>
            
</td>
            
<td>
                
<%= Html.Encode(item.Updator) %>
            
</td>
            
<td>
                
<%= Html.Encode(String.Format("{0:g}", item.UpdateDT)) %>
            
</td>
            
<td>
                
<%= Html.Encode(String.Format("{0:F0}", item.PkId)) %>
            
</td>
            
<td>
                
<%= Html.Encode(item.IsChanged) %>
            
</td>
            
<td>
                
<%= Html.Encode(item.IsDeleted) %>
            
</td>
        
</tr>
        
<% } %>
    
</table>
            
<%--<input type="button" id="show-btn" />--%>
    
<div id="hello-win" class="x-hidden">
    
<div id="form"></div>
<%--    <div class="x-window-header">Hello Dialog</div>
    
<div id="hello-tabs">
        
<!-- Auto create tab 1 -->
        
<div class="x-tab" title="Hello World 1">
            
<p>Hello...</p>
        
</div>
        
<!-- Auto create tab 2 -->
        
<div class="x-tab" title="Hello World 2">
            
<p>... World!</p>
        
</div>
    
</div>--%>
</div>
    
<%
    
//int PageCount = 0;
    
//if (Session["PageCount"] != null)
    
//{
    
//    PageCount = int.Parse(Session["PageCount"].ToString());
    
//}
    
//int currendSessionIndex=1;
    ////if(Session["CurrendIndex"]!=null)
    
////{
    
////    currendSessionIndex = int.Parse(Session["CurrendIndex"].ToString());
    
////}
    //currendSessionIndex = int.Parse(hidCurrentIndex.Value.ToString());
     %>
     
<%
         
int PageCount = 0;
         
if (ViewData["PageCount"!= null)
         {
             PageCount 
= int.Parse(ViewData["PageCount"].ToString());
         }
         
int currendSessionIndex = 1;
         
if (ViewData["CurrendIndex"!= null)
         {
             currendSessionIndex 
= int.Parse(ViewData["CurrendIndex"].ToString());
         }         
          
%>
    
<%= Html.ActionLink("首页""index"new { currentIndex =1})%>   <%=Html.ActionLink("上一页""index"new { currentIndex =currendSessionIndex,flag=0})%>   <%=Html.ActionLink("下一页""index"new { currentIndex = currendSessionIndex, flag = 1})%>  <%=Html.ActionLink("尾页""index"new { currentIndex=PageCount,flag=2 })%>

    
<p>
        
<%= Html.ActionLink("Create New""Create"%>
    
</p>
    
<%--<input type="button" id="btnXML" onclick="StartXMLRequest()" />--%>
</asp:Content>

 

Controller

所有你自己写的controller只需继承Controller类即可。他是modelview层之间的桥梁。前一票随笔所提到的service在这里将会使用到。

简单代码:



简单代码:
 
public class SystemConfigController : ControllerBase
    {
        SystemConfigService service 
= new SystemConfigService();
#if unitTest
        
int pageSize=5;
#else 
        
int pageSize = int.Parse(ConfigurationManager.AppSettings["PageSize"].ToString());
#endif
        
//
        
// GET: /SystemConfig/

        
/// <summary>
        
/// SystemConfig列表界面
        
/// </summary>
        
/// <param name="currentIndex">当前页</param>
        
/// <param name="flag">向前还是向后</param>
        
/// <returns>提交界面结果</returns>
        public ActionResult Index(int? currentIndex, int? flag)
        {
            
#region Session 实现
            
//int pageCount = service.GetPageCount(pageSize);
            
//Session["PageCount"] = pageCount;
            
//List<SystemConfig> configList = new List<SystemConfig>();
            
//if (currentIndex.HasValue)
            
//{
            
//    if (currentIndex.Value == 1)
            
//    {
            
//        //第一页,session CurrendIndex置为 1
            
//        if (currentIndex.Value == 1)
            
//        {
            
//            Session["CurrendIndex"] = 1;
            
//        }
            
//    }
            
//}
            
//if (flag.HasValue && currentIndex.HasValue)
            
//{
            
//    //0向前
            
//    if (flag.Value == 0)
            
//    {
            
//        Session["CurrendIndex"] = currentIndex.Value - 1;
            
//        currentIndex = currentIndex.Value - 1;
            
//        configList = service.GetByPage(currentIndex.Value, pageSize);
            
//    }
            
//    //1向后
            
//

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
在Asp.NetMVC中利用快递100接口实现订阅物流轨迹功能发布时间:2022-07-10
下一篇:
ASP.NET网站文件上传下载功能发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap