1. 程式人生 > >通過 SignalR 類庫,實現 ASP.NET MVC 的實時通訊

通過 SignalR 類庫,實現 ASP.NET MVC 的實時通訊

在本文中,您將學到在現有 ASP.NET MVC 框架的 CRUD 專案中,如何使用 SignalR 類庫,顯示來自資料庫的實時更新。在這一主題中,我們將重點放在在現有 ASP.NET MVC 框架的 CRUD 專案中,如何使用 SignalR 類庫,顯示來自資料庫的實時更新。 本文系國內 ITOM 管理平臺 OneAPM 工程師編譯整理。

本主題有以下兩個步驟:

  1. 我們將建立一個示例應用程式來執行 CRUD 操作。

  2. 我們將使用 SignalR 類庫讓應用實時。

那些不熟悉 SignalR 的,請訪問我以前有關 SignalR 概述 的文章。

第一步:

我們需要建立一個名為 CRUD_Sample 的資料庫。在示例資料庫中建立一個名為 Customer 的表。

CREATE TABLE [dbo].[Customer](  
  [Id] [bigint] IDENTITY(1,1)NOTNULL,  
  [CustName] [varchar](100)NULL,  
  [CustEmail] [varchar](150)NULL  
) 

儲存過程

USE [CRUD_Sample]  
GO  

/****** Object:  StoredProcedure [dbo].[Delete_Customer]    Script Date: 12/27/2015 1:44:05 PM ******/  
SETANSI_NULLSON  
GO  

SETQUOTED_IDENTIFIERON  
GO  

-- =============================================  
-- Author:
<Author,,Name> -- Create date: <Create Date,,> -- Description: <Description,,> -- ============================================= CREATE PROCEDURE [dbo].[Delete_Customer] -- Add the parameters for the stored procedure here @Id Bigint AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SETNOCOUNTON;
-- Insert statements for procedure here DELETE FROM [dbo].[Customers] WHERE [Id] = @Id RETURN 1 END GO /****** Object: StoredProcedure [dbo].[Get_Customer] Script Date: 12/27/2015 1:44:05 PM ******/ SETANSI_NULLSON GO SETQUOTED_IDENTIFIERON GO -- ============================================= -- Author: <Author,,Name> -- Create date: <Create Date,,> -- Description: <Description,,> -- ============================================= CREATE PROCEDURE [dbo].[Get_Customer] -- Add the parameters for the stored procedure here @Count INT AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SETNOCOUNTON; -- Insert statements for procedure here SELECT top(@Count)*FROM [dbo].[Customers] END GO /****** Object: StoredProcedure [dbo].[Get_CustomerbyID] Script Date: 12/27/2015 1:44:05 PM ******/ SETANSI_NULLSON GO SETQUOTED_IDENTIFIERON GO -- ============================================= -- Author: <Author,,Name> -- Create date: <Create Date,,> -- Description: <Description,,> -- ============================================= CREATE PROCEDURE [dbo].[Get_CustomerbyID] -- Add the parameters for the stored procedure here @Id BIGINT AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SETNOCOUNTON; -- Insert statements for procedure here SELECT*FROM [dbo].[Customers] WHERE [email protected] END GO /****** Object: StoredProcedure [dbo].[Set_Customer] Script Date: 12/27/2015 1:44:05 PM ******/ SETANSI_NULLSON GO SETQUOTED_IDENTIFIERON GO -- ============================================= -- Author: <Author,,Name> -- Create date: <Create Date,,> -- Description: <Description,,> -- ============================================= CREATE PROCEDURE [dbo].[Set_Customer] -- Add the parameters for the stored procedure here @CustNameNvarchar(100) ,@CustEmailNvarchar(150) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SETNOCOUNTON; -- Insert statements for procedure here INSERT INTO [dbo].[Customers]([CustName],[CustEmail]) VALUES(@CustName,@CustEmail) RETURN 1 END GO /****** Object: StoredProcedure [dbo].[Update_Customer] Script Date: 12/27/2015 1:44:05 PM ******/ SETANSI_NULLSON GO SETQUOTED_IDENTIFIERON GO -- ============================================= -- Author: <Author,,Name> -- Create date: <Create Date,,> -- Description: <Description,,> -- ============================================= CREATE PROCEDURE [dbo].[Update_Customer] -- Add the parameters for the stored procedure here @Id Bigint ,@CustNameNvarchar(100) ,@CustEmailNvarchar(150) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SETNOCOUNTON; -- Insert statements for procedure here UPDATE [dbo].[Customers] SET[CustName] = @CustName,[CustEmail]= @CustEmail WHERE [Id] = @Id RETURN 1 END GO

啟動 MVC 專案

建立示例應用程式,我們需要 Visual Studio 2012 或更高版本,並且該伺服器平臺必須支援 .NET 4.5。

步驟 1:

Getting Started with MVC

Step 2:

Web application

Step 3:

select template

點選 OK,Visual Studio 將會建立一個新的 ASP.NET 工程。

使用通用類庫

使用通用功能,我們可以減少程式碼數量。

namespace WebApplication1.Repository  
{  
    interfaceIRepository < T > : IDisposablewhereT: class  
    {  
        IEnumerable < T > ExecuteQuery(stringspQuery, object[] parameters);  
        TExecuteQuerySingle(stringspQuery, object[] parameters);  
        intExecuteCommand(stringspQuery, object[] parameters);  
    }  
}  

介面 IRepository

顯示一個通用類庫的 T 型介面,它是 SQL 實體的 LINQ。它提供了一個基本的介面操作,如 Insert, Update, Delete, GetById and GetAll。

IDisposable

IDisposable介面提供了一種機制,釋放非託管資源。

where T : class

這是制約泛型引數的一類。點選檢視更多

型別引數必須是引用型別;這也適用於任何類,介面,委託或陣列型別。

namespace WebApplication1.Repository  
{  
    public class GenericRepository < T > : IRepository < T > whereT: class  
    {  
        Customer_Entities context = null;  
        privateDbSet < T > entities = null;  
        public GenericRepository(Customer_Entities context)  
        {  
            this.context = context;  
            entities = context.Set < T > ();  
        }  
        ///<summary>  
        /// Get Data From Database  
        ///<para>Use it when to retive data through a stored procedure</para>  
        ///</summary>  
        public IEnumerable < T > ExecuteQuery(stringspQuery, object[] parameters)  
        {  
            using(context = newCustomer_Entities())  
            {  
                    returncontext.Database.SqlQuery < T > (spQuery, parameters).ToList();  
            }  
        }  
        ///<summary>  
        /// Get Single Data From Database  
        ///<para>Use it when to retive single data through a stored procedure</para>  
        ///</summary>  
        public TExecuteQuerySingle(stringspQuery, object[] parameters)  
        {  
            using(context = newCustomer_Entities())  
            {  
                returncontext.Database.SqlQuery < T > (spQuery, parameters).FirstOrDefault();  
            }  
        }  
        ///<summary>  
        /// Insert/Update/Delete Data To Database  
        ///<para>Use it when to Insert/Update/Delete data through a stored procedure</para>  
        ///</summary>  
        public intExecuteCommand(stringspQuery, object[] parameters)  
        {  
            int result = 0;  
            try  
            {  
                using(context = newCustomer_Entities())  
                {  
                    result = context.Database.SqlQuery < int > (spQuery, parameters).FirstOrDefault();  
                }  
            }  
            catch  
            {}  
            return result;  
        }  
        private bool disposed = false;  
        protected virtualvoid Dispose(bool disposing)  
        {  
            if (!this.disposed)  
            {  
                if (disposing)  
                {  
                    context.Dispose();  
                }  
            }  
            this.disposed = true;  
        }  
        public void Dispose()  
        {  
            Dispose(true);  
            GC.SuppressFinalize(this);  
        }  
    }  
} 

使用 middle-tire 結構

namespace WebApplication1.Services  
{  
    public partial class CustomerService  
    {  
        privateGenericRepository < Customer > CustRepository;  
        //CustomerRepositoryCustRepository;  
        public CustomerService()  
        {  
            this.CustRepository = newGenericRepository < Customer > (newCustomer_Entities());  
        }  
        public IEnumerable < Customer > GetAll(object[] parameters)  
        {  
            stringspQuery = "[Get_Customer] {0}";  
            returnCustRepository.ExecuteQuery(spQuery, parameters);  
        }  
        public CustomerGetbyID(object[] parameters)  
        {  
            stringspQuery = "[Get_CustomerbyID] {0}";  
            returnCustRepository.ExecuteQuerySingle(spQuery, parameters);  
        }  
        public int Insert(object[] parameters)  
        {  
            stringspQuery = "[Set_Customer] {0}, {1}";  
            returnCustRepository.ExecuteCommand(spQuery, parameters);  
        }  
        public int Update(object[] parameters)  
        {  
            stringspQuery = "[Update_Customer] {0}, {1}, {2}";  
            returnCustRepository.ExecuteCommand(spQuery, parameters);  
        }  
        public int Delete(object[] parameters)  
        {  
            stringspQuery = "[Delete_Customer] {0}";  
            returnCustRepository.ExecuteCommand(spQuery, parameters);  
        }  
    }  
}  

在 MVC 架構應用程式中使用通用庫

namespace WebApplication1.Controllers  
{  
    public class HomeController: Controller  
    {  
        private CustomerServiceobjCust;  
        //CustomerRepositoryCustRepository;  
        public HomeController()  
            {  
                this.objCust = newCustomerService();  
            }  
            // GET: Home  
        public ActionResult Index()  
        {  
            int Count = 10;  
            object[] parameters = {  
                Count  
            };  
            var test = objCust.GetAll(parameters);  
            return View(test);  
        }  
        public ActionResult Insert()  
        {  
            return View();  
        }  
        [HttpPost]  
        public ActionResult Insert(Customer model)  
        {  
            if (ModelState.IsValid)  
            {  
                object[] parameters = {  
                    model.CustName,  
                    model.CustEmail  
                };  
                objCust.Insert(parameters);  
            }  
            return RedirectToAction("Index");  
        }  
        public ActionResult Delete(int id)  
        {  
            object[] parameters = {  
                id  
            };  
            this.objCust.Delete(parameters);  
            return RedirectToAction("Index");  
        }  
        public ActionResult Update(int id)  
        {  
            object[] parameters = {  
                id  
            };  
            return View(this.objCust.GetbyID(parameters));  
        }  
        [HttpPost]  
        public ActionResult Update(Customer model)  
        {  
            object[] parameters = {  
                model.Id,  
                model.CustName,  
                model.CustEmail  
            };  
            objCust.Update(parameters);  
            return RedirectToAction("Index");  
        }  
        protected override void Dispose(bool disposing)  
        {  
            base.Dispose(disposing);  
        }  
    }  
} 

在 MVC 架構應用程式中使用檢視

Index

@model IList  
<WebApplication1.Models.Customer>  
@{  
ViewBag.Title = "Index";  
}  

    <linkhref="~/Content/bootstrap/css/bootstrap.min.css"rel="stylesheet"/>  
    <divclass="clearfix">   
    </div>  
    <divclass="clearfix">   
    </div>  
    <divclass="container">  
        <divclass="table-responsive">  
@Html.ActionLink("New Customer", "Insert", "Home")  

            <tableclass="table table-bordered table-striped">  
                <thead>  
                    <tr>  
                        <th>ID</th>  
                        <th>Name</th>  
                        <th>Email ID</th>  
                        <th>Delete</th>  
                        <th>Update</th>  
                    </tr>  
                </thead>  
                <tbody>  
                @if (Model != null)  
                {  
                    foreach (var item in Model)  
                    {  

                       <tr>  
                           <td>@item.Id</td>  
                           <td>@item.CustName</td>  
                           <td>@item.CustEmail</td>  
                           <td>@Html.ActionLink("Delete", "Delete", "Home", new { id = @item.Id }, null)</td>  
                           <td>@Html.ActionLink("Update", "Update", "Home", new { id = @item.Id }, null)</td>  
                       </tr>  
                    }  
                }  

                </tbody>  
            </table>  
        </div>  
        <divclass="clearfix">   
        </div>  
    </div> 

Insert

@model WebApplication1.Models.Customer  
@{  
ViewBag.Title = "Insert";  
}  

<link href="~/Content/bootstrap/css/bootstrap.min.css"rel="stylesheet"/>  
<div class="clearfix">   
</div>  
<div class="clearfix">   
</div>  
<div class="container">  
    <div class="table-responsive col-md-6 col-md-offset-3">  
        <table class="table table-bordered table-striped">  
            <tbody>  
@using (Html.BeginForm("Insert", "Home", FormMethod.Post))  
{  
@*  
                <tr>  
                    <td class="col-md-4">ID</td>  
                    <td class="col-md-8">@Html.TextBoxFor(m =>m.Id)</td>  
                </tr>*@  

                <tr>  
                    <td class="col-md-4">Name  
                    </td>  
                    <td class="col-md-8">@Html.TextBoxFor(m =>m.CustName)  
                    </td>  
                </tr>  
                <tr>  
                    <td class="col-md-4">Email ID  
                    </td>  
                    <td class="col-md-8">@Html.TextBoxFor(m =>m.CustEmail)  
                    </td>  
                </tr>  
                <tr>  
                    <td class="text-right"colspan="2">  
                        <input type="submit"value="Save"class="btnbtn-primary"/>  
                    </td>  
                </tr>  
}  

            </tbody>  
        </table>  
    </div>  
    <div class="clearfix">   
    </div>  
@Html.ActionLink("Home", "Index", "Home")  

</div>  

Update

@model WebApplication1.Models.Customer  
@{  
ViewBag.Title = "Update";  
}  


<link href="~/Content/bootstrap/css/bootstrap.min.css"rel="stylesheet"/>  
<div class="clearfix">   
</div>  
<div class="clearfix">   
</div>  
<div class="container">  
    <div class="table-responsive">  
        <table class="table table-bordered table-striped">  
            <thead>  
                <tr>  
                    <th>Name</th>  
                    <th>Email ID</th>  
                    <th>Update</th>  
                </tr>  
            </thead>  
            <tbody>  
                <tr>  
@using (Html.BeginForm("Update", "Home", FormMethod.Post))  
{  

                    <td>@Html.TextBoxFor(m =>m.CustName)</td>  
                    <td>@Html.TextBoxFor(m =>m.CustEmail)</td>  
                    <td>  
                        <inputtype="submit"value="Update"class="btnbtn-primary"/>  
                    </td>  
}  

                </tr>  
            </tbody>  
        </table>  
    </div>  
</div>  

步驟2:

啟動 SignalR

第一件事是獲得 NuGet 參照。

在 NuGet 上獲得。

註冊 SignalR 中介軟體

安裝後需要建立 OwinStartup 類。

下面的程式碼將一段簡單中介軟體向 OWIN 管道,實現接收 Microsoft.Owin.IOwinContext 例項的功能。

當伺服器收到一個 HTTP 請求,OWIN 管道呼叫中介軟體。中介軟體設定內容型別的響應和寫響應體。

Startup.cs

using System;  
using System.Threading.Tasks;  
using Microsoft.Owin;  
using Owin;  
[assembly: OwinStartup(typeof (WebAppSignalR.Startup))]  
namespace WebAppSignalR  
{  
    public class Startup  
    {  
        public void Configuration(IAppBuilder app)  
        {  
            app.MapSignalR();  
        }  
    }  
}  

建立使用 Hub 類

完成前面的過程之後,建立一個 Hub。一個SignalR Hub 讓從伺服器到客戶端連線,並從客戶端到伺服器的遠端過程呼叫(RPC)。

CustomerHub.cs

using System;  
using System.Collections.Generic;  
using System.Linq;  
using System.Web;  
using Microsoft.AspNet.SignalR;  
using Microsoft.AspNet.SignalR.Hubs;  
namespace WebApplication1.Hubs  
{  
    public class CustomerHub: Hub  
    {  
        [HubMethodName("broadcastData")]  
        public static void BroadcastData()  
        {  
            IHubContext context = GlobalHost.ConnectionManager.GetHubContext < CustomerHub > ();  
            context.Clients.All.updatedData();  
        }  
    }  
}  

程式碼說明

IHubContext context = GlobalHost.ConnectionManager.GetHubContext<CustomerHub>(); 

獲得 CustomerHub context:

context.Clients.All.updatedData();  

它請求 SignalR 的客戶端部分,並告訴它執行 JavaScript 的 updatedData()方法。

修改現有檢視 Let’s Modify our Existing View

修改一部分索引檢視,將通過區域性檢視顯示資料。

Index

@model IList < WebApplication1.Models.Customer > @  
{  
    ViewBag.Title = "Index";  
} < linkhref = "~/Content/bootstrap/css/bootstrap.min.css"  
rel = "stylesheet" / > < divclass = "clearfix" > & nbsp; < /div> < divclass = "clearfix" > & nbsp; < /div> < divclass = "container" > < divclass = "table-responsive" > @Html.ActionLink("New Customer", "Insert", "Home") < hr / > < divid = "dataTable" > < /div> < /div> < divclass = "clearfix" > & nbsp; < /div> < /div>  
@section JavaScript  
{ < scriptsrc = "~/Scripts/jquery.signalR-2.2.0.min.js" > < /script> < scriptsrc = "/signalr/hubs" > < /script> < scripttype = "text/javascript" > $(function ()  
    {  
        // Reference the hub.  
        var hubNotif = $.connection.customerHub;  
        // Start the connection.  
        $.connection.hub.start().done(function ()  
        {  
            getAll();  
        });  
        // Notify while anyChanges.  
        hubNotif.client.updatedData = function ()  
        {  
            getAll();  
        };  
    });  
    function getAll()  
    {  
        var model = $('#dataTable');  
        $.ajax(  
        {  
            url: '/home/GetAllData',  
            contentType: 'application/html ; charset:utf-8',  
            type: 'GET',  
            dataType: 'html'  
        }).success(function (result)  
        {  
            model.empty().append(result);  
        }).error(function (e)  
        {  
            alert(e);  
        });  
    } < /script>  
}  

區域性檢視

<table class="table table-bordered table-striped">  
    <thead>  
        <tr>  
            <th>ID</th>  
            <th>Name</th>  
            <th>Email ID</th>  
            <th>Delete</th>  
            <th>Update</th>  
        </tr>  
    </thead>  
    <tbody> @if (Model != null) { foreach (var item in Model) {  
        <tr>  
            <td>@item.Id</td>  
            <td>@item.CustName</td>  
            <td>@item.CustEmail</td>  
            <td>@Html.ActionLink("Delete", "Delete", "Home", new { id = @item.Id }, null)</td>  
            <td>@Html.ActionLink("Update", "Update", "Home", new { id = @item.Id }, null)</td>  
        </tr> } } </tbody>  
    </table> 

修改現有 Controller

主 Controller:

在主 Controller,我們將新增一個名為 GetAllDaTa()的方法。這是方法。

[HttpGet]  
public ActionResult GetAllData()  
{  
    int Count = 10;  
    object[] parameters = {  
        Count  
    };  
    var test = objCust.GetAll(parameters);  
    return PartialView("_DataList", test);  
}  

在這裡,返回區域性檢視返回的資料列表,且只返回空。

// GET: Home  
public ActionResult Index()  
{  
   return View();  
}  

主 Controller

public class HomeController: Controller  
{  
    private CustomerService objCust;  
    //CustomerRepositoryCustRepository;  
    public HomeController()  
    {  
        this.objCust = newCustomerService();  
    }  
    // GET: Home  
    public ActionResult Index()  
    {  
        return View();  
    }  
    [HttpGet]  
    public ActionResult GetAllData()  
    {  
        int Count = 10;  
        object[] parameters = {  
            Count  
        };  
        var test = objCust.GetAll(parameters);  
        return PartialView("_DataList", test);  
    }  
    public ActionResult Insert()  
    {  
        return View();  
    }  
    [HttpPost]  
    public ActionResult Insert(Customer model)  
    {  
        if (ModelState.IsValid)  
        {  
            object[] parameters = {  
                model.CustName,  
                model.CustEmail  
            };  
            objCust.Insert(parameters);  
        }  
        //Notify to all  
        CustomerHub.BroadcastData();  
        return RedirectToAction("Index");  
    }  
    public ActionResult Delete(int id)  
    {  
        object[] parameters = {  
            id  
        };  
        this.objCust.Delete(parameters);  
        //Notify to all  
        CustomerHub.BroadcastData();  
        return RedirectToAction("Index");  
    }  
    public ActionResult Update(int id)  
    {  
        object[] parameters = {  
            id  
        };  
        return View(this.objCust.GetbyID(parameters));  
    }  
    [HttpPost]  
    public ActionResult Update(Customer model)  
    {  
        object[] parameters = {  
            model.Id,  
            model.CustName,  
            model.CustEmail  
        };  
        objCust.Update(parameters);  
        //Notify to all  
        CustomerHub.BroadcastData();  
        returnRedirectToAction("Index");  
    }  
    protected override void Dispose(bool disposing)  
    {  
        base.Dispose(disposing);  
    }  
}  

輸出

output

希望能夠幫助到您。

OneAPM 助您輕鬆鎖定 .NET 應用效能瓶頸,通過強大的 Trace 記錄逐層分析,直至鎖定行級問題程式碼。以使用者角度展示系統響應速度,以地域和瀏覽器維度統計使用者使用情況。想閱讀更多技術文章,請訪問 OneAPM 官方部落格

相關推薦

通過 SignalR 實現 ASP.NET MVC實時通訊

在本文中,您將學到在現有 ASP.NET MVC 框架的 CRUD 專案中,如何使用 SignalR 類庫,顯示來自資料庫的實時更新。在這一主題中,我們將重點放在在現有 ASP.NET MVC 框架的 CRUD 專案中,如何使用 SignalR 類庫,顯示來自資

使用GMap.NET實現地圖軌跡回放。(WPF版)

前言 實現軌跡回放,GMap.NET有對應的類GMapRoute。這個類函式很少,功能有限,只能實現簡單的軌跡回放。要實現更復雜的軌跡回放,就需要自己動手了。 本文介紹一種方法,可以實現複雜的軌跡回放。有句話“功夫在詩外”,GMap.NET給你提供了基本地圖處理功能;但是不要讓CMap.NET束縛了手腳。

通過Himal項目學習掌握asp.net MVC

himall 源碼 asp.net mvc 最近學完了asp.net MVC,想找個項目練練手,偶然間找到了Himall系統源碼。首先介紹以下Himall這個系統。 HiMall多用戶商城系統(B2B2C+O2O),是一款帶O2O的多用戶商城系統,類似京東,天貓等大型購物多店鋪平臺,能夠幫助企業解

如何提高碼農產量基於ASP.NET MVC的敏捷開發框架開發隨筆一

公司業務量比較大,接了很多專案,為了縮短開發週期老闆讓我牽頭搭建了一個敏捷開發框架。 我們主要的業務是做OA、CRM、ERP一類的管理系統,一個通用的後臺搭出來,再配合一些快速開發的元件開發效率能提高很多。 另外老闆一再強調要支援APP開發,一次開發能部署到安卓和IOS上。

避開WebForm天坑擁抱ASP.Net MVC

有鵬友在如鵬網的QQ群中提了一個問題: 請問,在ASP.Net中如何隱藏一個MenuItem,我想根據不同的許可權,對功能選單進行隱藏,用style不行。 如果要僅僅解答這個問題,很好解答,答案很簡單: 給MenuItem設定Value,然後用從根節點開始的Me

【無私分享:從入門到精通ASP.NET MVC】從0開始一起搭框架、做專案(5.4) 登入功能的實現建立與登入使用者相關的介面和實現

索引 簡述 今天我們建立幾個與登入使用者相關的資料表的介面和實現類 專案準備 我們用的工具是:VS 2013 + SqlServer 2012 + IIS7.5 希望大家對ASP.NET MVC有一個初步的理解,理論性的東西我們不做過多解釋,有些地方不理解也沒關係,會用就行了,用的多了,用的久了

ASP.NET沒有魔法——ASP.NET MVC 與數據之EF實體與數據結構

類之間的關系 context 模型 rst 例子 style 方法 eid 一個   大家都知道在關系型數據庫中每張表的每個字段都會有自己的屬性,如:數據類型、長度、是否為空、主外鍵、索引以及表與表之間的關系。但對於C#編寫的類來說,它的屬性只有一個數據類型和類與類之間的關

通過ASP.NET MVC框架 + 原生JavaScript + Ajax + SQL SERVER 實現一個簡單的有論壇功能的網站(有通過iis發布的例子)

簡單的 接下來 發送 思維 學會 control javascrip 數據庫 今天   ASP.NET MVC. M 為Model模型層, V 為View視圖層, C 為Controller控制層。要想使用MVC框架來寫網站就需要了解M V C 的作用分別為哪些。給大家簡單

ASP.NET MVC項目實現BasePage基用作ASPX.CS網頁繼承

bsp targe 解決方法 網頁 接下來 項目開發 空間 所有 會有 在ASP.NET MVC項目開發,還是需要創建一些Web Page來實現一些功能,如呈現報表等... 但是一旦項目的.ASPX網頁太多了,其中的程序代碼也會有代碼冗余,出現這些情況,我們得需要對這些代

ASP.NET MVC 實現頁落網資源分享網站+充值管理+後臺管理(7)之擴充套件基和區域建立以及文字編輯配置

    一、擴充套件基類和區域建立     (1)在應用之前,我們先在表現層建立一個公共的系統擴充套件檔案來(SystemExtension)存放我們需要延伸和擴充套件的方法類。     在常規的專案系統操作中,我們都需要用到

通過ASP.NET MVC框架 + 原生JavaScript + Ajax + SQL SERVER 實現一個簡單的有論壇功能的網站(有通過iis釋出的例子)

  ASP.NET MVC. M 為Model模型層, V 為View檢視層, C 為Controller控制層。要想使用MVC框架來寫網站就需要了解M V C 的作用分別為哪些。給大家簡單的介紹一下:     1.當你的這個網站要與資料庫互動的時候,你可以使用EF建立一個數據庫模型,也可以用類存放你所需互動

NoSql-MongoDB GridFS+ASP.NET MVC實現上傳顯示

namespace MongoDBTest.Controllers { public class MongoDBHelperController : Controller { private static MongoDatabase DB; public sta

Crawler/ML:爬蟲技術(基於urllib.request從網頁獲取圖片)+HierarchicalClustering層次聚演算法實現自動從網頁獲取圖片然後根據圖片色調自動分類

網上教程太囉嗦,本人最討厭一大堆沒用的廢話,直接上,就是幹! 網路爬蟲?非監督學習? 只有兩步,只有兩個步驟? Are you kidding me? Are you ok? 來吧,follow me, come on! 一、爬蟲下載圖片 第一步:首先,我們從網

PHP通過PHPMailer實現QQ郵箱傳送方法

其實PHP郵箱傳送功能並非每個專案都一定用得到,但其實每個完整的專案,一般都會包含一個PHP郵箱傳送功能。 一般郵箱傳送功能普遍用於註冊啟用,密碼找回,以及留言回覆等等功能上。而且這也是很多人頭疼的問

38、對比Java標準NIO你知道Netty是如何實現更高效能的嗎?

今天我會對 NIO 進行一些補充,在專欄第 11 講中,我們初步接觸了 Java 提供的幾種 IO 機制,作為語言基礎類庫,Java 自身的 NIO 設計更偏底層,這本無可厚非,但是對於一線的應用開發者,其複雜性、擴充套件性等方面,就存在一定的侷限了。在基礎 NIO 之上,Netty&nb

【無私分享:從入門到精通ASP.NET MVC】從0開始一起搭框架、做專案(5.3) 登入功能的實現豐富資料表、建立關聯

1 USE [wkmvc_db] 2 GO 3 /****** Object: Table [dbo].[SYS_CODE] Script Date: 2016/5/17 9:30:01 ******/ 4 SET ANSI_NULLS ON 5 GO 6 SET

【無私分享:從入門到精通ASP.NET MVC】從0開始一起搭框架、做專案(5.5) 登入功能的實現完善登入功能

索引 簡述 今天我們來完善我們的登入功能 專案準備 我們用的工具是:VS 2013 + SqlServer 2012 + IIS7.5 希望大家對ASP.NET MVC有一個初步的理解,理論性的東西我們不做過多解釋,有些地方不理解也沒關係,會用就行了,用的多了,用的久了,自然就理解了。 專案開

【無私分享:從入門到精通ASP.NET MVC】從0開始一起搭框架、做專案(5.2) 登入功能的實現介面注入、log4net的使用

索引 簡述 前兩天事情比較多,耽誤更新了,希望大家多多包涵,今天我們繼續做我們的登入功能 專案準備 我們用的工具是:VS 2013 + SqlServer 2012 + IIS7.5 希望大家對ASP.NET MVC有一個初步的理解,理論性的東西我們不做過多解釋,有些地方不理解也沒關係,會用就行

【無私分享:從入門到精通ASP.NET MVC】從0開始一起搭框架、做專案(5.1) 登入功能的實現開始接觸Spring IOC、DI

索引 簡述 今天我們做登入,今天的東西比較多,用到了Spring的IOC和DI、介面的使用、驗證等,希望大家多多討論 專案準備 我們用的工具是:VS 2013 + SqlServer 2012 + IIS7.5 希望大家對ASP.NET MVC有一個初步的理解,理論性的東西我們不做過多解釋,有些

【無私分享:從入門到精通ASP.NET MVC】從0開始一起搭框架、做專案(6) 控制器基 主要做登入使用者、許可權認證、日誌記錄等工作

索引 簡述 今天我們來寫一個控制器基類 主要做登入使用者、許可權認證、日誌記錄等工作 專案準備 我們用的工具是:VS 2013 + SqlServer 2012 + IIS7.5 希望大家對ASP.NET MVC有一個初步的理解,理論性的東西我們不做過多解釋,有些地方不理解也沒關係,會用就行了,