Mvc图像上传无法正常工作

Mvc图像上传无法正常工作

本文介绍了Mvc图像上传无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的价值总是空值,



我尝试过:



控制器,



I got always null value for this,

What I have tried:

Controller,

if (itm.AttachmentModel.AttachmentFile != null)
               {
                   itm.AttachmentModel.AttachmentURL = string.Format("{0}.{1}", Guid.NewGuid().ToString(), itm.AttachmentModel.AttachmentFile.FileName.Split('.')[1]);
                   if (itm.AttachmentModel.AttachmentFile != null)
                   {

                       var path = Path.Combine(Server.MapPath("~/App_Data/Attachments/"), itm.AttachmentModel.AttachmentURL);
                       itm.AttachmentModel.AttachmentFile.SaveAs(path);
                   }
               }





查看,





View,

<input type="hidden" value="" name="..."><input type="file" name="AttachmentFile">





模态,





Modal,

public HttpPostedFileBase AttachmentFile { get; set; }
    public string AttachmentURL
    {
        get
        {
            return attachment;
        }

        set
        {
            attachment = value;
        }
    }

    public string Attachment
    {
        get
        {
            return attachment;
        }

        set
        {
            attachment = value;
        }
    }

推荐答案


这篇关于Mvc图像上传无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-10 12:04