ASPNET MVC3技术要点(12)

发布时间:2021-06-06

ASPNET MVC3技术要点

repository.Products.Count() : repository.Products.Where(e => e.Category == category).Count() },

CurrentCategory = category };

return View(viewModel); }

视图

@model SportsStore.WebUI.Models.ProductsListViewModel @{

ViewBag.Title = "Products"; }

@foreach (var p in Model.Products) {

Html.RenderPartial("ProductSummary", p); }

<div class="pager">

@Html.PageLinks(Model.PagingInfo, x => Url.Action("List", new {page = x, category = Model.CurrentCategory})) </div>

嵌入视图ProductSummary.cshtml

@model SportsStore.Domain.Entities.Product

<div class="item">

@if (Model.ImageData != null) {

<div style="float:left;margin-right:20px">

<img width="75" height="75" src="@Url.Action("GetImage", "Product", new { Model.ProductID })" /> </div> }

<h3>@</h3> @Model.Description

@using(Html.BeginForm("AddToCart", "Cart")) { @Html.HiddenFor(x => x.ProductID)

@Html.Hidden("returnUrl", Request.Url.PathAndQuery) <input type="submit" value="+ Add to cart" /> }

<h4>@Model.Price.ToString("c")</h4> </div>

为了实现动作函数的参变量传送,定义路由映射

routes.MapRoute(null,

"", // Only matches the empty URL (i.e. /)

new {

controller = "Product",

ASPNET MVC3技术要点(12).doc 将本文的Word文档下载到电脑

精彩图片

热门精选

大家正在看

× 游客快捷下载通道(下载后可以自由复制和排版)

限时特价:7 元/份 原价:20元

支付方式:

开通VIP包月会员 特价:29元/月

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信:fanwen365 QQ:370150219