码迷,mamicode.com
首页 > 其他好文 > 详细

通过id查询出图片

时间:2017-05-30 15:51:38      阅读:241      评论:0      收藏:0      [点我收藏+]

标签:model   style   html   select   分享   ida   UI   publish   路径   

第一步,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="#=PictureThumbnailUrl#" />,
                                            width: 200,
                                            attributes: { style: "text-align:center" }

                                        }

 

通过id查询出图片

标签:model   style   html   select   分享   ida   UI   publish   路径   

原文地址:http://www.cnblogs.com/bfwbfw/p/6920098.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!