官术网_书友最值得收藏!

  • ASP.NET MVC 2 Cookbook
  • Andrew Siemer, Richard Kimber
  • 301字
  • 2021-04-09 22:44:22

Chapter 1. Working with the View

In this chapter, we will cover:

  • Using magic strings and the ViewData dictionary
  • Creating a strongly typed view
  • Decoupling a strongly typed view with a View Model
  • Centralizing display logic with templated helpers
  • Using a partial view to segment view code
  • Rendering a child view with Html.RenderAction
  • Building a view from the database with NVelocity
  • Consuming a JSON view with jQuery

Introduction

In this chapter, we will take a look at the easiest part of the whole ASP.NET MVC framework—the View. We will get started by looking at how data is passed out to the view in the simplest of ways using the ViewData dictionary and magic strings. From there, we will work towards better ways of getting data in and out of the view. Then we will take a look at some of the other view engines that you have at your disposal, which can easily be plugged into the ASP.NET MVC framework. Finally, we will take a look at other things that you can do with the view.

In our examples, we will be working with the basic concept of products and categories as though we were building a simple e-commerce site. We will be using an open source product called NBuilder to fake our data access layer. NBuilder will be used to quickly generate some product and category data for us to use in our views.

Note

NBuilder is a great open source product that can be used to quickly generate test instances of a particular .NET class. This works great when knocking together your views such as we are doing in this chapter. You can find more data about NBuilder at NBuilder.org. I also wrote a tutorial on how to get NBuilder running on DotNetSlackers.com at dotnetslackers.com/articles/aspnet/Using-NBuilder-to-mock-up-a-data-driven-UI-Part1.aspx.

主站蜘蛛池模板: 新津县| 榆林市| 澎湖县| 日土县| 兴化市| 德安县| 来安县| 巴马| 娱乐| 长葛市| 资源县| 荥经县| 陕西省| 霍邱县| 监利县| 广平县| 汶上县| 化德县| 北辰区| 马山县| 天气| 德惠市| 漳平市| 科技| 江安县| 梓潼县| 调兵山市| 渭源县| 石首市| 建宁县| 通海县| 肥东县| 乐昌市| 枣强县| 临泉县| 赣榆县| 如皋市| 荣成市| 长治县| 民县| 邻水|