C# 使用弹出式表单、MVC和AJAX始终';空';

C# 使用弹出式表单、MVC和AJAX始终';空';,c#,jquery,sql-server,ajax,model-view-controller,C#,Jquery,Sql Server,Ajax,Model View Controller,我正在使用本文中的代码将行上载到SQL Server表,其中一个新要求是将文件存储到服务器中以用于“证据”目的,因此在表单中我有以下代码: @using (Html.BeginForm("AnadirLic", "Licencia", FormMethod.Post, new { enctype = "multipart/form-data", onsubmit = "return SubmitForm(this)" })) { @Html.HiddenFor(model => m

我正在使用本文中的代码将行上载到SQL Server表,其中一个新要求是将文件存储到服务器中以用于“证据”目的,因此在表单中我有以下代码:

@using (Html.BeginForm("AnadirLic", "Licencia", FormMethod.Post, new { enctype = "multipart/form-data", onsubmit = "return SubmitForm(this)" }))
{
    @Html.HiddenFor(model => model.idLicencia)
<div class="form-group">
                    <label>Tipo de especialista: </label>

                    @Html.DropDownList("tipoEspecialista", new List<SelectListItem>{
                    new SelectListItem{ Value="1", Text = "Medico"},
                    new SelectListItem{ Value="2", Text = "Dentista"},
                    new SelectListItem{ Value="3", Text = "Matrona"},})

                    <small class="form-text text-muted">Ejercicio</small>
                </div>
                <div class="form-group">
                    <label>Cargar Evidencia</label>
                    @*@Html.TextBoxFor(model => model.rutaEvidencia, new { @class = "form-control", @type = "file" })*@
                    @*@Html.TextBoxFor(model => model.rutaEvidencia, new { @class = "form-control", @type = "file", enctype = "multipart/form-data" })*@
                    <input type="file" id="FileUpload" />
                    <small class="form-text text-muted">Máximo 4MB, .pdf, .jpg, .png</small>
                </div>

                <div class="input-group">
                    <input type="submit" value="Subir" class="btn btn-primary" style="margin-right:10px"/>
                    <input type="reset" value="Limpiar campos" class="btn btn-primary" />
                </div>
@使用(Html.BeginForm(“AnadirLic”、“licensia”、FormMethod.Post、new{enctype=“multipart/formdata”、onsubmit=“return SubmitForm(this)”)
{
@Html.HiddenFor(model=>model.idLicencia)
特别提示:
@Html.DropDownList(“Tipoeta”),新列表{
新建SelectListItem{Value=“1”,Text=“Medico”},
新建SelectListItem{Value=“2”,Text=“Dentista”},
新建SelectListItem{Value=“3”,Text=“Matrona”},})
埃塞尔奇奥
卡加证据
@*@Html.TextBoxFor(model=>model.rutaEvidencia,新的{@class=“form control”,@type=“file”})*@
@*@Html.TextBoxFor(model=>model.rutaEvidencia,新的{@class=“form control”,@type=“file”,enctype=“multipart/form data”})*@
Máximo 4MB、.pdf、.jpg、.png
AJAX函数如下所示:


函数PopupForm(url){
var formDiv=$('');
$.get(url)
.完成(功能(响应){
html(回应);
Popup=formDiv.dialog({
自动打开:对,
可调整大小:正确,
标题:“Llenar nuevo reposo”,
身高:500,
宽度:1300,
关闭:函数(){
对话框('destroy').remove();
}
})
}
)
}
函数提交表单(表单){
$.validator.unobtrusive.parse(表单);
//文件验证程序/计数
var totalFiles=document.getElementById(“FileUpload”).files.length;
对于(var i=0;i
允许您选择单个文件。在“提交”功能中,您正在访问“文件”属性,该属性仅可用于多个文件选择

因此,要么在输入标签中添加多个

修改提交功能以使用“值”属性而不是文件属性

function SubmitForm(form) {
    $.validator.unobtrusive.parse(form);
// FILE VALIDATOR / COUNT
    /*var totalFiles = document.getElementById("FileUpload").files.length;
    for (var i = 0; i < totalFiles; i++) {
        var archivo = document.getElementById("FileUpload").files[i];
        form.append("FileUpload", archivo);
    }*/
    var archivo = document.getElementById("FileUpload").Value;
    form.append("FileUpload", archivo);
//IF VALID UPLOAD TO SQL
    if ($(form).valid()) {
        $.ajax({
            type: "POST",
            url: form.action,
            data: $(form).serialize(),
            success: function (data) {
                if (data.success) {
                    Popup.dialog('close');

                    $('#tablaLicencia').DataTable().ajax.reload()

                    $.notify(data.message, {
                        globalPosition: "top center",
                        className: "success"
                    })

                }
            }
        });
    }
    return false;
}
函数提交表单(表单){
$.validator.unobtrusive.parse(表单);
//文件验证程序/计数
/*var totalFiles=document.getElementById(“FileUpload”).files.length;
对于(var i=0;i