三层架构(3-tier application) 通常意义上的三层架构就是将整个业务应用划分为:表现层(UI)、业务逻辑层(BLL)、数据访问层(DAL)。区分层次的目的即为了“高内聚,低耦合”的思想。
1、表现层(UI):通俗讲就是展现给用户的界面,即用户在使用一个系统的时候他的所见所得。
2、业务逻辑层(BLL):针对具体问题的 *** 作,也可以说是对数据层的 *** 作,对数据业务逻辑处理。
3、数据访问层(DAL):该层所做事务直接 *** 作数据库,针对数据的增添、删除、修改、更新、查找等。
MVC是 Model-View-Controller,严格说这三个加起来以后才是三层架构中的UI层,也就是说,MVC把三层架构中的UI层再度进行了分化,分成了控制器、视图、实体三个部分,控制器完成页面逻辑,通过实体来与界面层完成通话;而C层直接与三层中的BLL进行对话。
上学期教同学时写了一个绝对适合入门的小例子 用的是asp.net mvc3+linq to entitylinq to entity和linq to sql在使用上本身差距不大 你肯定能看懂的
*razor页面中用的是弱类型的helper
还有疑问可以去此论坛.net区提问:
http://bbs.ctrlc.com.cn/
欢迎交流
原文地址:http://user.qzone.qq.com/523080653/blog/1300030445
--------------------------------------------------------------------------------------------------------------
今天给同学演示用的demo 无美工无分层无XXXXXX 三无产品 绝对适合入门...
就一张表 UserInfo{UserID,UserName,UserPassword}
逻辑写controller里了 model里就一个实体 就不列出来了
HomeController
using System
using System.Collections.Generic
using System.Linq
using System.Web
using System.Web.Mvc
using TestDemo.Models
using System.Data.Objects
namespace TestDemo.Controllers
{
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
TestEntities te = new TestEntities()
ObjectQuery<UserInfo>userInfos = te.UserInfoes
var users = from u in userInfos
select u
ViewData.Model = users.ToList()
return View()
}
public ActionResult Delete(int id)
{
TestEntities te = new TestEntities()
ObjectQuery<UserInfo>userInfos = te.UserInfoes
var query = userInfos.Single(u =>u.UserID == id)
te.DeleteObject(query)
te.SaveChanges()
return RedirectToAction("Index")
}
public ActionResult Add()
{
return View()
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Add(FormCollection form)
{
TestEntities te = new TestEntities()
UserInfo addUser = new UserInfo()
{
UserName = form["userName"].ToString(),
UserPassword = form["userPassword"].ToString()
}
te.UserInfoes.AddObject(addUser)
te.SaveChanges()
return RedirectToAction("Index")
}
public ActionResult Edit(int id)
{
TestEntities te = new TestEntities()
ObjectQuery<UserInfo>userInfos = te.UserInfoes
UserInfo user = userInfos.Single(u =>u.UserID == id)
ViewData.Model = user
return View()
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult Edit(FormCollection form)
{
TestEntities te = new TestEntities()
ObjectQuery<UserInfo>userInfos = te.UserInfoes
int id = Int32.Parse( form["userID"].ToString())
var query = from u in userInfos
where u.UserID == id
select u
UserInfo editUser = query.First()
UserInfo user = new UserInfo()
{
UserID=id,
UserName = form["userName"].ToString(),
UserPassword = form["userPassword"].ToString()
}
editUser.UserName = user.UserName
editUser.UserPassword = user.UserPassword
te.SaveChanges()
return RedirectToAction("Index")
}
}
}
Add.cshtml
@{
ViewBag.Title = "Add"
}
<h2>Add</h2>
@using (Html.BeginForm())
{
@Html.Label("姓名")
@Html.TextBox("userName")
<hr />
@Html.Label("密码")
@Html.TextBox("userPassword")
<input type="submit" value="提交"/>
}
Edit.cshtml
@using TestDemo.Models
@{
ViewBag.Title = "Edit"
}
<h2>
Edit</h2>
@using (Html.BeginForm())
{
UserInfo query = ViewData.Model
@Html.Label("ID", query.UserID.ToString())
<br />
@Html.Label("姓名")
@Html.TextBox("userName")<br />
@Html.Label("密码")
@Html.TextBox("userPassword")<br />
@Html.Hidden("userID", query.UserID)
<input type="submit" value="提交" />
}
Index.cshtml
@using TestDemo.Models
@{
ViewBag.Title = "Index"
}
<!DocType html />
<html>
<head>
<title></title>
<link href="@Url.Content("../Content/Test.css")" type="text/css" rel="Stylesheet" />
</head>
<body>
<div class="all" >
<div class="top">
</div>
<div class="content">
@{
List<UserInfo>users = ViewData.Model
@Html.ActionLink("添加", "Add")
<table id="qzw">
@foreach (UserInfo user in users)
{
<tr>
<td>@user.UserID
</td>
<td>@user.UserName
</td>
<td>@user.UserPassword
</td>
<td>@Html.ActionLink("删除", "Delete", new { id = user.UserID })
</td>
<td>@Html.ActionLink("修改", "Edit", new { id = user.UserID })
</td>
</tr>
}
</table>
}
</div>
</div>
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)