首页 > 代码库 > 通过id查询出图片

通过id查询出图片

第一步,model中需要如下的做法

  [UIHint("Picture")]  //加上之后会默认显示上传图片的模式
public int PictrueId { get; set; }

public string PictureThumbnailUrl { get; set; }//路径

技术分享

 

第二步,控制器中

                             aaModel m=new aaModel ();
                    //picture
                    var defaultProductPicture = _pictureService.GetPictureById(x.PictrueId);
                    m.PictureThumbnailUrl = _pictureService.GetPictureUrl(defaultProductPicture, 75, true);

  附加一些理解使用的代码(可省略):

 [HttpPost]
        public virtual ActionResult List(GZUCarouselPicModel model, DataSourceRequest command, string key)
        {

            var info = _carouselPicService.GetAllGZUCarouselPics().Where(x => x.Area.Contains(key)).ToList();
            var Pageinfo = new PagedList<GZUCarouselPic>(info, command.Page - 1, command.PageSize);

            //load Pageinfo  

            var gridModel = new DataSourceResult
            {
                Data = Pageinfo.Select(x =>
                {
                    var m = x.ToModel();
                    m.IsPublish = x.IsPublish;
                    m.IsPublishStr = x.IsPublish ? "" : "";

                    //picture
                    var defaultProductPicture = _pictureService.GetPictureById(x.PictrueId);
                    m.PictureThumbnailUrl = _pictureService.GetPictureUrl(defaultProductPicture, 75, true);
                    return m;
                }),
                Total = Pageinfo.TotalCount
            };

            return Json(gridModel);
        }

 第三步,页面中

<div class="form-group">
                    <div class="col-md-3">
                        @Html.NopLabelFor(model => model.PictrueId)
                    </div>
                    <div class="col-md-6">
                        @Html.NopEditorFor(model => model.PictrueId)
                        @Html.ValidationMessageFor(model => model.PictrueId)
                    </div>
                </div>

 第四步,Lsit中

                                       {
                                            field: "PictureThumbnailUrl",
                                            title: "@T("Admin.GZUCarouselPic.PictrueId")",
                                            template: <img src="http://www.mamicode.com/#=PictureThumbnailUrl#" />,
                                            width: 200,
                                            attributes: { style: "text-align:center" }

                                        }

 

通过id查询出图片