在MVC应用程序中显示数据库中的图像 [英] Displaying an image from a database in a MVC Application

查看:53
本文介绍了在MVC应用程序中显示数据库中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想知道是否有人知道如何在MVC视图中显示数据库中的图像?目前我有一个上传视图,允许用户上传图像,所有这些图像都显示在编辑视图的网页中,图像记录旁边有一个删除按钮。我想要删除按钮将用户带到一个新视图,其中显示他们点击的图像,以便他们知道他们正在删除正确的图像,



我有为新的DeleteItemImage功能设置单独的视图和控制器,它将显示图像,但此刻所有都是空的,



任何帮助将不胜感激,



尼克



这是我在编辑视图中的图像webgrid的代码:



Hi,

I was wondering if anybody knows how to Display an image from a database in a MVC view? At the moment I have an upload view which allows a user to upload an image and all these images are displayed in a webgrid in a Edit view with a "Delete" button next to image record. I want the Delete button to take the user to a new view where the image they have clicked on is displayed so they know they are deleting the correct one,

I have set up separate views and controllers for the new "DeleteItemImage" function which will display the image, but all are empty at the moment,

Any help would be appreciated,

Nick

Here is my code for the Images webgrid in the Edit view:

        <table style="width:100%">
              @{
var imagesGrid = new WebGrid(Model.ItemImages);
               }
                @imagesGrid.GetHtml(tableStyle: "webgrid",
        headerStyle: "webgrid-header",
        footerStyle: "webgrid-footer",
        alternatingRowStyle: "webgrid-alternating-row",
        selectedRowStyle: "webgrid-selected-row",
        rowStyle: "webgrid-row-style",
        (columns: imagesGrid.Columns(
                imagesGrid.Column("Sequence_No_", header: "Sequence No"),
                imagesGrid.Column("Image_Title", header: "Image Title"),
                imagesGrid.Column("Main_Image", header: "Primary Image"),
                imagesGrid.Column("Uploaded", header: "Uploaded to LinnWorks"),
                imagesGrid.Column("",
            format: @<text>
                     @Html.ActionLink("Delete", "DeleteItemImage");
                    </text>),
                imagesGrid.Column("",
            format:@<text>
                    @Html.ActionLink("Select", null, new { selectImage = Model.SelectImage })
                </text>),
            imagesGrid.Column("",
            format:@<text>
                    @Html.ActionLink("Make Primary", null, new { makePrimary = Model.MakeMainImage })
                    </text>
            ))))

        </table>





这是我的编辑操作结果的代码:



Here is my code for the Edit action result:

public ActionResult Edit(string itemNo)
{
        LinnWorksItemViewModel model = new LinnWorksItemViewModel(_data.Connection.ConnectionString, itemNo);
        return View(model);

        foreach (string upload in Request.Files)
        {
            if (!Request.Files[upload].HasFile()) continue;
            string path = AppDomain.CurrentDomain.BaseDirectory + "uploads/";
            string fileName = Path.GetFileName(Request.Files[upload].FileName);
            Request.Files[upload].SaveAs(Path.Combine(path, fileName));
        }
        return View(model);
}

推荐答案

你的行动结果中的一个错误是你的第二个

One bug in your action result is that your second
return view(model); 



不起作用,因为当你返回一个模型时,你不能返回另一个模型!


will not work, because when you return a model , you can't return another model!


这篇关于在MVC应用程序中显示数据库中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆