在db中插入照片路径

时间:2014-07-23 09:19:06

标签: c# asp.net-mvc plupload

我有这样的数据库:

enter image description here

我有文本框在我的数据库中写入值的用途。一切顺利,除了照片。我想写一下使用plupload上传的图片路径。

我可以从db中检索照片,如果我将插入这样的路径:“〜/ Uploads / 1.jpg”,但是当我上传这些文件时,我无法在数据库中写下它的名字。

这是使用我上传照片的代码:

<div id="container">
            <a id="pickfiles" href="javascript:;">[Select files]</a>
            <a id="uploadfiles" href="javascript:;">[Upload files]</a>
        </div>

<script type="text/javascript" src="../Scripts/plupload.full.min.js"></script>
<script type="text/javascript">

    var uploader = new plupload.Uploader({
        runtimes: 'html5,flash,silverlight,html4',
        browse_button: 'pickfiles',
        container: document.getElementById('container'),
        url: '/Admin/Upload',
        flash_swf_url: 'Scripts/Moxie.swf',
        silverlight_xap_url: 'Scripts/Moxie.xap',

        filters: {
            max_file_size: '10mb',
            mime_types: [
                { title: "Image files", extensions: "jpg,gif,png" },
                { title: "Zip files", extensions: "zip" }
            ]
        },

        init: {
            PostInit: function () {
                document.getElementById('uploadfiles').onclick = function () {
                    uploader.start();
                    return false;
                };
            },


            UploadProgress: function (up, file) {

                alert("File has succesfully added");
            },

            Error: function (up, err) {
                alert("\nError #" + err.code + ": " + err.message);
            }
        }
    });

    uploader.init();

</script>

这是我的添加操作,使用我在DB中插入值:

[HttpGet]
    public ActionResult Add()
    {
        return View();
    }

    [HttpPost]
    public ActionResult Add
        (
        string Name, string Company, int Age, string Position, string Quote, string Biography,
        string Type, string Industry, string Founders, string AreaServed, string Products, 
        string WebPage, string Facebook, int PhoneNumber, string Email, string Photo
        )
    {


        Biography BioDb = new Biography();
        BioDb.Name = Name;
        BioDb.Company = Company;
        BioDb.Age = Age;
        BioDb.Position = Position;
        BioDb.Quote = Quote;
        BioDb.Biography1 = Biography;
        BioDb.Type = Type;
        BioDb.Industry = Industry;
        BioDb.Founders = Founders;
        BioDb.AreaServed = AreaServed;
        BioDb.Products = Products;
        BioDb.WebPage = WebPage;
        BioDb.Facebook = Facebook;
        BioDb.Phone = PhoneNumber;
        BioDb.Email = Email;
        BioDb.Photo = "~/Uploads/" + Photo;

        BIOEntities bio = new BIOEntities();

        bio.Biographies.AddObject(BioDb);
        bio.SaveChanges();

        return View();
    }

当我正在调试时,Photo是 null ,而在db中只插入〜/ Uploads /(这是文件夹的名称)。我想在db~ / Uploads / +中插入用户上传的照片名称。

任何人都可以告诉我该怎么做?

感谢

1 个答案:

答案 0 :(得分:0)

如果有人需要这个:

我添加了照片名称的文本框:

<div class="editor-label">
            @Html.LabelFor(model => model.Photo)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Photo)
            @Html.ValidationMessageFor(model => model.Photo)
        </div>

这在上传中:

 UploadProgress: function (up, file) {
                _file_name = file.name;
               $('#Photo').val(_file_name);

            }
一切顺利。

由于