PageAdmin网站内容管理系统(CMS)交流论坛

注册

 

QQ登录

只需一步,快速开始

发新话题 回复该主题

如何在前端调用新增加的字段 [复制链接]

1#
4的新版本里,在product增加了新字段price,请问如何在List.cshtml 页面中调取?
分享 转发
TOP
2#

回复 1楼netxm的帖子
  1.     @foreach (var item in Html.InfoDataList(new{Table="product"}))
  2.     {
  3.    ....
  4.       <span>@item.Price</span>
  5.      }
复制代码
字段第一个字母要大写
TOP
3#

“....”
的内容能一并列出吗?我想调用产品名称时与价格一起展示出来
TOP
4#

这个只是演示数据怎么调,页面数据和内容怎么排版你要自己写html部分
调字段格式就是@item.字段,字段一个字母大写就可以调出来。
TOP
5#

我现在能调用了,但对应不了一产品一价格,即全部价格都会列出。如何调整呢?

                <div class="Price">
                      @foreach (var item in Html.InfoDataList(new{Table="product"}))
                      {
                       string url = Html.InfoDataUrl((int)item.ColumnId, (int)item.Id);
                       string Price = item.Price;
                    <div class="price">产品价格</div>
                      <span>@item.Price</span>
                        }
                </div>
TOP
6#

人家版主意思是模板中你只调用@item.Price 这句就可以调出价格了,不是让你所有的复制进去,人才
TOP
7#

因为不懂,所以要问,我只想知道我在product/Detail.cshtml 这文件中调用产品名称时,如何同时调用对应的价格(后台新添加了字段)
TOP
8#

Detail.cshtml  内容发出来
TOP
9#

  1. @{
  2.     int columnId = Html.CurrentColumnId();
  3.     dynamic infoData = Html.InfoData();
  4.     dynamic prevData = Html.InfoDataPrevious(columnId, (int)infoData.Id);
  5.     dynamic nextData = Html.InfoDataNext(columnId, (int)infoData.Id);
  6.     string relativeIds = infoData.RelativeIds;//获取相关产品的ids;
  7. }
  8. <div class="container padding-top-20">
  9.     <div class="row">
  10.         <div class="col-md-3">
  11.             @Html.Partial("subNavPartial")
  12.         </div>
  13.         <div class="col-md-9">
  14.             @Html.Partial("BreadcrumbPartial")
  15.             <div class="clearfix product-content">
  16.                 <div>
  17.                     <!--图片组-->
  18.                     @Html.Partial("DetailImagesModel", Html.AttachmentDataList(new { ParentTable = "product", ParentField = "images", ParentId = (int)infoData.Id }))
  19.                 </div>
  20.                 
  21.                <!--4.26 16:25-->
  22.                 <div class="Price">
  23.                       @foreach (var item in Html.InfoDataList(new{Table="product"}))
  24.                       {
  25.                        string url = Html.InfoDataUrl((int)item.ColumnId, (int)item.Id);
  26.                        string Price = item.Price;
  27.                       <span>@item.Price</span>
  28.                         }
  29.                 </div>
  30.                 
  31.                 <!--产品介绍-->
  32.                 <div class="detail padding-top-20">
  33.                     <div class="title">产品介绍</div>
  34.                     <div class="info-content padding-top-20">
  35.                         @Html.Raw(infoData.Content)
  36.                     </div>
  37.                 </div>

  38.             </div>
  39.             <div class="clearfix padding-top-20 line-height-2">
  40.                 <ul>
  41.                     @if (prevData != null)
  42.                     {
  43.                         string url = Html.InfoDataUrl((int)prevData.ColumnId, (int)prevData.Id);
  44.                         <li class="text-gray">上一篇:<a href="@url">@prevData.Title</a></li>
  45.                     }
  46.                     @if (nextData != null)
  47.                     {
  48.                         string url = Html.InfoDataUrl((int)nextData.ColumnId, (int)nextData.Id);
  49.                         <li class="text-gray">下一篇:<a href="@url">@nextData.Title</a></li>
  50.                     }
  51.                 </ul>
  52.             </div>
  53.             <!--相关推荐-->
  54.             @if (!string.IsNullOrEmpty(relativeIds))
  55.             {
  56.                 <div class="recommend">
  57.                     <div class="public-title">
  58.                         相关推荐
  59.                     </div>
  60.                     @{
  61.                         var relativeList = Html.InfoDataList(new { Table = "product", ShowNumber = 8, OrderBy = "thedate desc" }, "id in(" + relativeIds + ")");
  62.                         <div class="images-list imgae-same-size padding-top-20" id="productList">
  63.                             <div class="row">
  64.                                 @foreach (dynamic item in relativeList)
  65.                                 {
  66.                                     string url = Html.InfoDataUrl((int)item.ColumnId, (int)item.Id);
  67.                                     string thumbnail = item.Thumbnail;
  68.                                   string price = item.Price;
  69.                                     <div class="col-md-3 col-sm-4 col-xs-6 item">
  70.                                         <a href="@url" target="_blank"><img src="@thumbnail" alt="@item.Title"></a>
  71.                                         <a href="@url" target="_blank" class="text-center line-height-3 font-weight-600">
  72.                                             @item.Title
  73.                                             @item.Price
  74.                                         </a>
  75.                                     </div>
  76.                                 }
  77.                             </div>
  78.                         </div>
  79.                     }
  80.                 </div>
  81.                         }

  82.         </div>
  83.     </div>
  84. </div>
  85. <script type="text/javascript">
  86.     var $lb_clicks = $("#lb_clicks");
  87.     $.post("/E/InfoData/AddClicks", { ColumnId:@infoData.ColumnId,Id:@infoData.Id}, function (data) { $lb_clicks.text(data)})
  88. </script>
复制代码
最后编辑netxm 最后编辑于 2021-04-25 17:28:19
TOP
10#

搞定了,谢谢
TOP
发新话题 回复该主题