使用JTable和MVC.NET进行文件上传

时间:2016-05-16 10:27:41

标签: java jquery model-view-controller

我正在为学校管理创建一个简单的应用程序。我在哪里创建一个由老师注册的学生表格。我很容易创建它,但现在我想在注册表中添加学生的图像。 我在互联网上通过各种方式尝试了它,但没有运气。 请帮我。下面是我为html表单尝试的代码

img: {
                title: 'Img',
                width: '50%',
                display: function (data) {
                    return "<img src='../content/uploads/" + data.record.id + "/" + data.record.img + "' width='50' >";
                },
                input: function (data) {
                    debugger;
                    // data.value will be undefined on create method so we will show only input file tag
                    if (typeof data.value === "undefined") {
                        return '<div><input type="file" name="photo" id="photo" class="upload"/></div>';
                    }
                    else {
                        // on edit method we will show the image and the input file tag
                        return '<div><input type="file" name="photo" id="photo" class="upload"/></div>' +
                           '<div><img style="margin:5px;" src="../content/uploads/' + data.record.qid + '/' + data.value + '"  width="50" /></div>';
                    }
                }
            }

//createAction: '@Model.AddAction', this is commented here fot upload process
            createAction: function (postData) {
                return $.Deferred(function ($dfd) {
                    debugger;
                    var formData = new FormData(document.forms[0]);
                    $.ajax({
                        url: '@Url.Action("Add")',
                        type: 'POST',
                        data: formData,
                        processData: false,
                        contentType: false,
                        dataType: 'json',
                        success: function (data) {
                            $dfd.resolve(data);
                        }
                    });
                });

我的控制器和视图路径是AppRoot \ Areas \ Admin \ Views \ ManageStudent

当我提交此表单时,它给出了如下错误 http://localhost:62997/Admin/function%20(postData)%20%7B%20%20%return%20 $递延(函数%20($​​ DFD)%20%7B%20%20%无功%20formData%20 =%20new%20FormData(document.forms [0]);%20%20 $。 AJAX(%7B%20%20url:%20&#39; /管理/ ManageStudent /添加&#39;,%20%20type:%20&#39; POST&#39;,%20%数据:%20formData,%20% 20processData:%20false,%20%20%20contentType:%20false,%20%20%数据类型:%20&#39; JSON&#39;,%20%20%的成功:%20function%20(数据)%20%7B %$ dfd.resolve(数据);%20%20%);%207D);%20 %% 7D

请帮忙!

0 个答案:

没有答案