ASPNET MVC3技术要点(11)
发布时间:2021-06-06
发布时间:2021-06-06
ASPNET MVC3技术要点
视图
@{
ViewBag.Title = "Index"; }
<h2>Index</h2> <p>
The day is: @(((DateTime)ViewData["Date"]).DayOfWeek) </p> <p>
The message is: @ViewData["Message"] </p> <p />
<h4>InlineHelper</h4> Days of the week: <p/>
@Html.CreateList((string[]) ViewBag.Days) <p />
Fruit I like: <p />
@Html.CreateList((string[]) ViewBag.Fruits) <p />
@Html.DropDownList("region", "Choose")
3.2.2.3 使用ViewModel ViewModel
public class ProductsListViewModel {
public IEnumerable<Product> Products { get; set; } public PagingInfo PagingInfo { get; set; } public string CurrentCategory { get; set; } }
动作函数
public ViewResult List(string category, int page = 1) {
ProductsListViewModel viewModel = new ProductsListViewModel {
Products = repository.Products
.Where(p => category == null || p.Category == category) .OrderBy(p => p.ProductID) .Skip((page - 1) * PageSize) .Take(PageSize),
PagingInfo = new PagingInfo {
CurrentPage = page, ItemsPerPage = PageSize, TotalItems = category == null ?
上一篇:S3C44B0 学习板使用指南
下一篇:朗文交互英语第二级A2答案