asp MVC将上传的文件设置为“Include in Project”;也就是上传后显示图像 [英] asp MVC set uploaded file to "Include in Project" aka display image after upload

查看:92
本文介绍了asp MVC将上传的文件设置为“Include in Project”;也就是上传后显示图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我终于想到了如何在MVC上运行图像文件上传功能,但由于某种原因,一旦文件上传它'设置'它没有设置为从项目中排除状态,但我希望能够上传成功后,在下一个完成页面上显示上传的图像。有谁知道如何将上传文件的默认状态设置为包含在项目中?不确定这是我需要实现的设置还是一段代码。



So I finally figured how to get a image file upload function on MVC working but for some reason once the file uploads it''s set it''s not set to "exclude from project" status but I want to be able to display the uploaded image on the next "Completion page" once the upload is successful. Does anyone know how to set the default status of uploaded files to "include in project"? Not sure if it''s a setting or a piece of code I need to implement.

[AcceptVerbs(HttpVerbs.Get)]
public ActionResult PersonalProfile()
{
    return View();
}

[AcceptVerbs(HttpVerbs.Post)]
public ActionResult PersonalProfile( string photo_filename)
{
    if (Request.Files["photo"] != null) // If uploaded synchronously
    {
        photo_filename = _fileStore.SaveUploadedFile(Request.Files["photo"]);

    }

   // ViewData["photo_guid"] = photo_guid.Value;
    ViewData["photo_filename"] = photo_filename;
    return View("Completed");
}







</head>
    <body>
        <div id="MainContents">
            <h1>Thanks</h1>
            We have stored your photo <b><%= ViewData["photo_filename"]%></b>
            <br />
            <img src="" alt="" /> //image to be displayed
        </div>
    </body>

推荐答案

如果文件在您的服务器上,您可以使用它。没有项目可以包含在内,每次有人请求页面时你都不会重建你的dll,是吗?
If the file is on your server, you can use it. There is no project for it to be included in, you''re not rebuilding your dll every time someone requests a page, are you ?


只是想出它是什么......我上传到〜/ App_Data文件夹中名为Files的文件夹....一旦我将文件移动到根...一切正常
Just figured out what it was....I was uploading to a folder called "Files" in the ~/App_Data folder....once I moved "Files" to the root..everything works fine


这篇关于asp MVC将上传的文件设置为“Include in Project”;也就是上传后显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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