[回馈]ASP.NET Core MVC开发实战之商城系统(四)

这篇具有很好参考价值的文章主要介绍了[回馈]ASP.NET Core MVC开发实战之商城系统(四)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

经过一段时间的准备,新的一期【ASP.NET Core MVC开发实战之商城系统】已经开始,在之前的文章中,讲解了商城系统的整体功能设计,页面布局设计,环境搭建,系统配置,及首页【商品类型,banner条,友情链接,降价促销,新品爆款】,商品列表页面等功能的开发,今天继续讲解商品详情功能开发,仅供学习分享使用,如有不足之处,还请指正。

[回馈]ASP.NET Core MVC开发实战之商城系统(四)

 

商品详情功能说明

 

首页和商品列表,都是只展示商品的主要信息,如商品名称,商品价格,类型等内容,让人有一个先入为主的商品概念,当用户对商品有兴趣时,可以点击链接跳转商品详情页面,查看商品更全面的信息,如:颜色,尺寸等内容。

 

商品详情功能设计

 

根据商品详情页面功能说明,在此页面,用户可以查看商品的具体内容,如:图片,颜色,大小,类型,标签以及加入购物车,立即购买等功能,具体页面设计如下所示:

[回馈]ASP.NET Core MVC开发实战之商城系统(四)

 

商品详情页面功能开发

 

商品详情主要展示商品信息和商品配置信息。

 

1. 数据表创建

 

关于商品表EB_Product和对应模型Product的创建,可参考第二篇文章。商品配置表EB_ProductConfig,主要配置商品的特殊属性,如:颜色,尺寸,缩略图等内容,如下所示:

[回馈]ASP.NET Core MVC开发实战之商城系统(四)

创建表的语句,如下所示:

CREATE TABLE [dbo].[EB_ProductConfig](
	[Id] [bigint] IDENTITY(1,1) NOT NULL,
	[ProductId] [bigint] NULL,
	[ConfigType] [varchar](50) NULL,
	[ConfigName] [varchar](50) NULL,
	[ConfigValue] [varchar](150) NULL,
	[CreateTime] [datetime] NULL,
	[CreateUser] [varchar](50) NULL,
	[LastEditTime] [datetime] NULL,
	[LastEditUser] [varchar](50) NULL
) ON [PRIMARY]

 

2. 商品配置实体创建

 

商品配置表对应的项目模型实体,和数据表一一对应,如下所示:

namespace EasyBuyShop.Models
{
    /// <summary>
    /// 产品配置,主要配置颜色,大小,缩略图路径等
    /// </summary>
    [SqlSugar.SugarTable("EB_ProductConfig")]
    public class ProductConfig : EntityModel
    {
        public long ProductId { get; set; }

        public string ConfigType { get; set; }

        public string ConfigName { get; set; }

        public string ConfigValue { get; set; }
    }
}

 

3. 数据处理层DAL

 

商品详情页面主要根据商品ID获取商品的详细信息以及商品配置信息,如下所示:

商品详细信息在ProductDal中,如下所示:

public Product GetProduct(long Id)
{
    try
    {
        using (var db = this.GetDb(BaseDal.ConnStr))
        {
            return db.Queryable<Product>().First(r=>r.Id==Id);
        }
    }
    catch (Exception ex)
    {
        LogHelper.Fatal(ex.Message);
        return null;
    }
}

商品配置信息在ProductConfigDal中,获取配置信息如下所示:

using EasyBuyShop.Models;
using EasyBuyShop.Utils;

namespace EasyBuyShop.DAL
{
    public class ProductConfigDal : BaseDal
    {
        public ProductConfigDal()
        {
           
        }

        /// <summary>
        /// 获取产品配置
        /// </summary>
        /// <param name="productId"></param>
        /// <returns></returns>
        public List<ProductConfig> GetProductConfigListById(long productId)
        {
            try
            {
                using (var db = this.GetDb(BaseDal.ConnStr))
                {
                    return db.Queryable<ProductConfig>().Where(r => r.ProductId == productId).ToList();
                }
            }
            catch (Exception ex)
            {
                LogHelper.Fatal(ex.Message);
                return new List<ProductConfig>();
            }
        }
    }
}

 

4. 控制器获取

 

商品详细信息在ProductController的Detail方法中,根据传入的ID进行读取,如下所示:

public IActionResult Detail(int Id)
{
    var username = HttpContext.Session.GetString("username");
    var realName = HttpContext.Session.GetString("realname");
    ViewData["Username"] = username;
    ViewData["RealName"] = realName;
    ProductDal productDal = new ProductDal();
    ProductConfigDal productConfigDal = new ProductConfigDal();
    var product = productDal.GetProduct(Id);
    var productConfigList = productConfigDal.GetProductConfigListById(Id);
    ViewData["ProductConfigList"]=productConfigList;
    ViewData["Product"] = product;
    return View();
}

将获取到的Product对象和ProductConfigList列表对象通过ViewData传递到View视图层中进行展示。

 

5. 视图层展示

 

在Views/Product/Detail.cshtml中,接收控制器方法传递的数据,并进行展示。如下所示:

@{
    ViewData["Title"] = "商品详情";
}
@{
    var product = ViewData["Product"] as Product;
    var productConfigList = ViewData["ProductConfigList"] as List<ProductConfig>;
}
<div class="">
    <form method="post" id="detailForm">
        <input type="hidden" name="productId" value="@(product.Id)" />
        <input type="hidden" name="color" id="color" value="" />
        <input type="hidden" name="size" id="size" value="" />
        <!-- quick view start -->
        <div class="container">
            <div class="row">
                <div id="view-gallery">
                    <div class="col-xs-12">
                        <div class="d-table" style="width:100%">
                            <div class="d-tablecell">
                                <div class="main-view modal-content">
                                    <div class="row">
                                        <div class="col-xs-12 col-sm-5">
                                            <div class="quick-image">
                                                <div class="single-quick-image tab-content text-center">
                                                    @{
                                                        var productConfigImages = productConfigList.Where(r => r.ConfigType == "Image").ToList();
                                                        for (int i = 0; i < productConfigImages.Count; i++)
                                                        {
                                                            var productConfigImage = productConfigImages[i];
                                                            <div class="tab-pane  fade in @(i==0?"active":"")" id="sin-pro-@(i)">
                                                                <img src="@(productConfigImage.ConfigValue)" alt="">
                                                            </div>
                                                        }
                                                    }
                                                </div>
                                                <div class="quick-thumb">
                                                    <div class="nav nav-tabs">
                                                        <ul style="padding-left:0px;">
                                                            @{
                                                                for (int i = 0; i < productConfigImages.Count; i++)
                                                                {
                                                                    var productConfigImage = productConfigImages[i];
                                                                    <li><a data-toggle="tab" href="##" onclick="javascript:tabProductImage('sin-pro-@(i)',this);"> <img src="@(productConfigImage.ConfigName)" alt="quick view" style="width:90px;height:90px;"> </a></li>
                                                                }
                                                            }
                                                        </ul>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                        <div class="col-xs-12 col-sm-7">
                                            <div class="quick-right">
                                                <div class="quick-right-text">
                                                    <h3><strong>@product.Name</strong></h3>
                                                    <div class="rating">
                                                        <i class="fa fa-star"></i>
                                                        <i class="fa fa-star"></i>
                                                        <i class="fa fa-star"></i>
                                                        <i class="fa fa-star-half-o"></i>
                                                        <i class="fa fa-star-o"></i>
                                                    </div>
                                                    <div class="amount">
                                                        <h4>$@product.PreferentialPrice</h4>
                                                    </div>
                                                    <p>@product.Description</p>
                                                    <div class="row m-p-b">
                                                        <div class="col-sm-12">
                                                            <div class="por-dse responsive-strok clearfix">
                                                                <ul>
                                                                    <li><span>是否现货</span><strong>:</strong> 现货</li>
                                                                    <li><span>是否新品</span><strong>:</strong> 新品</li>
                                                                    <li>
                                                                        <span>商品类型</span><strong>:</strong>
                                                                        <a href="">@product.BasicStyle</a>
                                                                        <a href="">@product.ProductStyle</a>
                                                                    </li>
                                                                </ul>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="row m-p-b">
                                                        <div class="col-sm-12">
                                                            <div class="por-dse color">
                                                                <ul>
                                                                    <li>
                                                                        <span>颜色分类</span><strong>:</strong>
                                                                        <div class="por-dsc-div">
                                                                            @{
                                                                                var productColors = productConfigList.Where(r => r.ConfigType == "Color").ToList();
                                                                                for (int i = 0; i < productColors.Count; i++)
                                                                                {
                                                                                    <span class="por-dsc-span" onclick="javascript:checkActive(this,'color');">@(productColors[i].ConfigValue)</span>
                                                                                }
                                                                            }
                                                                        </div>
                                                                    </li>
                                                                    <li>
                                                                        <span>大小</span><strong>:</strong>
                                                                        <div class="por-dsc-div">
                                                                            @{
                                                                                var productSizes = productConfigList.Where(r => r.ConfigType == "Size").ToList();
                                                                                for (int i = 0; i < productSizes.Count; i++)
                                                                                {
                                                                                    <span class="por-dsc-span" onclick="javascript:checkActive(this,'size');">@(productSizes[i].ConfigValue)</span>
                                                                                }
                                                                            }
                                                                        </div>
                                                                    </li>
                                                                    <li>
                                                                        <span>标签</span><strong>:</strong>
                                                                        <a href="">@product.BasicStyle</a>
                                                                        <a href="">@product.ProductStyle</a>
                                                                    </li>
                                                                </ul>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="dse-btn">
                                                        <div class="row">
                                                            <div class="col-sm-12 col-md-12">
                                                                <div class="por-dse clearfix">
                                                                    <ul>
                                                                        <li class="share-btn clearfix">
                                                                            <span>数量</span>
                                                                            <input class="input-text qty" name="quantity" maxlength="12" value="1" title="数量" type="text">
                                                                        </li>
                                                                    </ul>
                                                                </div>
                                                            </div>
                                                            <div class="col-sm-12 col-md-12">
                                                                <div class="por-dse add-to" style="display:inline-block">
                                                                    <a href="##" onclick="javascript:addCartByForm();">加入购物车</a>
                                                                </div>
                                                                <div class="por-dse add-to" style="display:inline-block">
                                                                    <a href="##" onclick="javascript:addPurchaseByForm();">立即购买</a>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- quick view end -->
    </form>
</div>
<script src="~/js/shop.js"></script>

 

商品详情页面展示

 

运行程序,在首页或商品列表页面,点击商品链接,进入商品详情页面,如下所示:

[回馈]ASP.NET Core MVC开发实战之商城系统(四)

以上就是ASP.NET Core MVC开发实战之商城系统第四部分内容,后续将继续介绍其他模块,敬请期待。文章来源地址https://www.toymoban.com/news/detail-618813.html

到了这里,关于[回馈]ASP.NET Core MVC开发实战之商城系统(四)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • [回馈]ASP.NET Core MVC开发实战之商城系统(一)

    经过一段时间的准备,新的一期【ASP.NET Core MVC开发实战之商城系统】已经开始,今天着重讲解布局设计,环境搭建,系统配置,及首页商品类型,banner条,友情链接等功能的开发。     首页是商城系统的门面,首页的设计的好坏关系着用户的体验,在本示例中,首页主要分

    2024年02月16日
    浏览(33)
  • [回馈]ASP.NET Core MVC开发实战之商城系统(开篇)

    在编程方面,从来都是实践出真知,书读百遍其义自见,所以实战是最好的提升自己编程能力的方式。 前一段时间,写了一些实战系列文章,如: ASP.NET MVC开发学生信息管理系统 Vue+Antdv+Asp.net WebApi开发学生信息管理系统 WPF+Prism+MAH+Asp.net Web Api开发学生信息管理系统 ASP.NET C

    2024年02月16日
    浏览(40)
  • [回馈]ASP.NET Core MVC开发实战之商城系统(完:内附源码)

    经过一段时间的准备,【ASP.NET Core MVC开发实战之商城系统】已经完成,目前代码已开发完成,先将全部内容整理分享,如有不足之处,还请指正。     本系列文章主要讲解了商城系统的整体功能设计,页面布局设计,环境搭建,系统配置,及首页【商品类型,banner条,友情

    2024年02月11日
    浏览(33)
  • asp.net core 框架搭建2-搭建MVC后台管理系统

    作者:xcLeigh 文章地址:https://blog.csdn.net/weixin_43151418/article/details/131458964 asp.net core 框架搭建2-搭建MVC后台管理系统 ,本文章介绍asp.net core框架搭建,然后开发一个后台管理系统,将一步步带着大家,实现目标。所有操作过程将展现在本篇文章,下面咋们一起来实现它吧。 使

    2024年02月12日
    浏览(32)
  • ASP.NET Core MVC -- 将视图添加到 ASP.NET Core MVC 应用

    右键单击“视图”文件夹,然后单击“添加”“新文件夹”,并将文件夹命名为“HelloWorld”。 右键单击“Views/HelloWorld”文件夹,然后单击“添加”“新项”。 在“添加新项 - MvcMovie”对话框中: 在右上角的搜索框中,输入“视图” 选择“Razor 视图 - 空” 保持“名称”框的

    2024年02月13日
    浏览(62)
  • ASP.NET Core MVC -- 入门

     带有 ASP.NET 和 Web 开发工作负载的Visual Studio Visual Studio Code Visual Studio Code 用于 Visual Studio Code 的 C#(最新版本) .NET 7.0 SDK  ctrl + F5 (开始执行,不调试) 在代码工作区间文件夹路径下打开终端运行下面的命令  通过运行以下命令来信任 HTTPS 开发证书: 编译运行

    2024年02月11日
    浏览(32)
  • ASP.NET Core 中的 MVC架构

    MVC架构把 App 按照逻辑分成三层: Controllers,接收 http request,配合 model,通过http response 返回 view,尽量不做别的事 Models, 负责业务逻辑,App 的状态,以及数据处理 Views,呈现 UI,如果UI 较复杂,应该使用View 组件, ViewModel, 或者 view 模板 Controller ASP.NET Core MVC 中的所有 Control

    2024年02月09日
    浏览(29)
  • ASP.NET Core MVC -- 控制器

    默认控制器访问index 特定访问路径   特定路径访问,带参数

    2024年02月12日
    浏览(36)
  • 基于ASP.NET MVC开发的、开源的个人博客系统

    推荐一个功能丰富、易于使用和扩展的开源博客,可以轻松地创建和管理自己的博客。 基于.Net Framework 4.5开发的、开源博客系统,具有丰富的功能,包括文章发布、分类、标签、评论、订阅、统计等功能,同时也可以根据需要进行自定义扩展。 提供了丰富的配置选项和API,

    2024年02月14日
    浏览(39)
  • ASP.NET Core MVC 使用 JWT 的示例

    创建一个 ASP.NET Core MVC 项目。 添加 NuGet 包: Microsoft.AspNetCore.Authentication.JwtBearer:用于支持 JWT 的身份验证。 System.IdentityModel.Tokens.Jwt:用于生成和验证 JWT。 在 Startup.cs 文件中做如下修改: 请注意,在上述代码中,您需要将以下参数替换为实际的值: \\\"your_issuer\\\" :发行者的标

    2024年02月13日
    浏览(31)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包