1、微软ASPNET 框架的最大缺陷是ViewState导致页面的数据过大,从而使得页面的处理速度过慢;
<!DOCTYPE html>
<html>
<head runat="server">
<meta name="viewport" content="width=device-width" />
<title>View1</title>
</head>
<body>
<div>
<%= ViewData.Model.Name %>
</div>
</body>
</html>
2、基本术语学习()
@Styles.Render("~/Content/css");用于加载App_Start中
@Html.ActionLink("主页", "Index", "Home") 用于链接的创建,第一个参数是链接的内容名称,第二个参数是控制器中的视图;第三个参数是控制器;
@RenderBody()将模板页和子页面合并,并进行显示;
@RenderPage("")用于显示共享的视图页面;
@RenderSection("")用于显示节字段;
@model MvcApplication1.Models.LocalPasswordModel 引入模型数据;
3、基本的框架:
MVC框架分为三个部分MVC,即模型、视图和控制器。模型层负责数据的操作和获取,视图层负责数据的显示,控制层负责逻辑的显示与处理。
控制器和视图之间的传值方式包括,
1)通过ViewData的键值形式传值,视图层通过直接解析数据键值获取数据。
2)通过强制数据类型传递数据,这种方式最灵活,因为可以随意的指定View的地址。
3)通过指定Routing的形式进行数据的默认传值。
4、MVC框架能够很好的将程序的各个部分进行分解,从而能够更好的实现代码结构,但是对于代码的调试效率不如ASP.NET高。
5、Demo实现
1)创建前端View
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<MvcApplication1.Models.Test>" %>
<!DOCTYPE html>
<html>
<head runat="server">
<meta name="viewport" content="width=device-width" />
<title>View1</title>
</head>
<body>
<div>
<%= ViewData.Model.Name %>
</div>
</body>
</html>
2)创建Controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication1.Models;
namespace MvcApplication1.Controllers
{
public class TestController : Controller
{
//
// GET: /Test/
public ActionResult Index()
{
Test test = new Test();
test.Name = "zhangsan";
test.Code = "001";
return View("View1",test);
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MvcApplication1.Models
{
public class Test
{
public string Name;
public string Code;
}
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MvcApplication1.Models;
namespace MvcApplication1.Controllers
{
public class TestController : Controller
{
//
// GET: /Test/
public ActionResult Index()
{
Test test = new Test();
test.Name = "zhangsan";
test.Code = "001";
return View("View1",test);
}
}
}
3)创建Model
using System;using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace MvcApplication1.Models
{
public class Test
{
public string Name;
public string Code;
}
}
4)调试完成测试;
6、ASP.NET的MVC与Struct有着非常类似的功能,相比于SPRING MVC的灵活性还差很多。从这一点来看,微软对于新的框架的支持有一定的延后,开源的东西未必会比收费的东西差,关键是得有一个好的想法,并且坚持不懈执行的团队。