如何将图像保存到mysql数据库,保存后必须在相同的位置显示 [英] how to save images to mysql database and after saving it has to be displayed in the same

查看:94
本文介绍了如何将图像保存到mysql数据库,保存后必须在相同的位置显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

Iam在视图页面中设计了一个表单,该表单看起来像

Helo

Iam designed an form in view page which looks like

<div id="dialog" title="Upload files">
    @using(Html.BeginForm("Upload","Image", FormMethod.Post, new {id="photouploadform", enctype = "multipart/form-data" }))
    {
        <p><input type="file" id="fileUpload" name="fileUpload" size="23"/> </p><br />
        <p><input type="submit" value="Upload file" /></p>
        <input type="hidden" id="Id" value="1" />
    }
</div>

<script type="text/javascript">
    $(function () {
        $('.photoupload').click(function (event) {
            $('#userid').val(event.target.id);
            $('#dialog').dialog('open');
        });

        $('#photouploadform').submit(function () {
            $.getJSON("/Image/Upload/", {
                userid: $('#Id').val(),
                file1: $('#fileUpload')
            },
            function(success){
            alert(str.st)
            },
            function (data) {
                $('#dialog').append('<p>' + data + '</p>');
            });
            return false;
        });

        $("#dialog").dialog({
            autoOpen: false,
            show: "blind",
            width: 400,
            hide: "fade",
            modal: true,
            resizable: false

        });

    });
</script>




在我的控制器中,我给




In my controller i give like

public ActionResult Upload(int userid,HttpPostedFileBase file1)
       {

           Image g = new Image();
           g.Userid = userid;

           if (file1 != null)
           {
               g.Image1 = file1;
           }

           try
           {
               this.dbContext.Add(g);
               this.dbContext.SaveChanges();
           }
           catch
           {

           }

           var str = new { st = "Successfully Saved" };

           return Json(str, JsonRequestBehavior.AllowGet);
       }


当我单击上载时,它显示服务器错误
参数字典包含方法"System.Web.Mvc.ActionResult Upload(Int32,System.Web.HttpPostedFileBase)"中非空类型"System.Int32"的参数"Id"的空条目``Dataview.Controllers.ImageController''.可选参数必须是引用类型,可为空的类型,或者必须声明为可选参数.
谁能知道,请告诉我解决方案


when i click upload it is showing server error
The parameters dictionary contains a null entry for parameter ''Id'' of non-nullable type ''System.Int32'' for method ''System.Web.Mvc.ActionResult Upload(Int32, System.Web.HttpPostedFileBase)'' in ''Dataview.Controllers.ImageController''. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Can any one knows please tell me the solution

推荐答案

(function(){
(function () {


('.photoupload').click (函数(事件){
('.photoupload').click(function (event) {


('#userid').val(event.target.id);
('#userid').val(event.target.id);


这篇关于如何将图像保存到mysql数据库,保存后必须在相同的位置显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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