使AngularJS指令正常运行

时间:2016-01-26 16:36:42

标签: javascript html angularjs asp.net-mvc

我有一个HTML表单,如下所示:

<div>

    <div class="modal-header">
        <h3 class="modal-title">File Attachment</h3>
    </div>

    <div class="modal-body">
        <input type="file" id="inpFile" file-model="myFile" />
    </div>

    <div class="modal-footer">
        <div class="btn-toolbar pull-right" role="toolbar">
            <div class="btn-group" role="group" >
                <button type="button" class="btn btn-default" file-upload>Upload</button>
            </div>
            <div class="btn-group" role="group">
                <button type="button" class="btn btn-default" ng-click="$close()">Close</button>
            </div>
        </div>
    </div>

</div>

我有我的角度指令(在我的HTML中的上传statemtn中写的

.directive('fileUpload', ['$http', function ($http)
                {
                    return {
                        restrict: 'A',
                        link: function (scope, element, attrs)
                        {
                            // Create the formdata and get the file
                            var file = document.getElementById("inpFile").files[0];
                            var formdata = new FormData();
                            formdata.append('uploadedFile', file);

                            ajaxUrl = root + 'FileUpload/upload';
                            $http.post(ajaxUrl, formdata, {
                                headers: { "Content-Type": undefined }
                            })
                            .success(function (status)
                            {
                                if (status.Succeed)
                                {
                                    alert('File Uploaded');
                                }
                                else
                                {
                                    alert(status.ErrorResult);
                                }
                            });
                        }
                    };
                }])

以下是右上角附件屏幕的屏幕截图: enter image description here

我遇到的问题是: 当我点击该附件按钮时,HTML表单不会出现,以便我浏览,选择文件并单击上传按钮(指令所在的位置)。

相反,当点击附件按钮时,它会直接进入指令。之后它会进入我的MVC控制器,但没有文件可以验证,因为表单没有出现。

有人可以告诉我我在这里做错了所以表格将首先选择文件,点击上传按钮,然后让我的指令将文件提交给MVC控制器... < / p>

修改

Attchment代码按钮,出现在几个页面上:

<h3 class="panel-title">Check Deposit Header Information <attachment /> </h3>

表单是HTML表单的第一个屏幕截图。

我在想,当您点击“附件”按钮时,应该会出现HTML表单。当你点击上传按钮时,它应该点击指令。

当您单击“附件”链接时,HTML代码位于名为的目录中: AccountingModule /模态/附接/附着-modal.html

0 个答案:

没有答案