ASPNET MVC3技术要点(12)
发布时间:2021-06-06
发布时间: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",
上一篇:S3C44B0 学习板使用指南
下一篇:朗文交互英语第二级A2答案