JSon和List <httppostedfilebase> </httppostedfilebase>

时间:2015-02-05 07:30:32

标签: json httppostedfilebase

我有这个页面,我想上传一些文件。 在同一页面上,我也保存了其他数据。

这是我页面上的脚本:

        var skillNames = new Array();
    $('#frm').submit(function () {
        if ($(this).valid()) {
            $("li").each(function () {
                if ($(this).hasClass("search-choice")) {
                    var name = $(this).text().trim();
                    skillNames.push(name);
                };
            });

            var dataObject = JSON.stringify({
                'SkillNames': skillNames,
                'FirstName': $('#@Html.IdFor(u => u.CandidateInfo.FirstName)').val(),
                'Lastname': $('#@Html.IdFor(u => u.CandidateInfo.LastName)').val(),
                'Email': $('#@Html.IdFor(u => u.CandidateInfo.Email)').val(),
                'PrimaryPhone': $('#@Html.IdFor(u => u.CandidateInfo.PrimaryPhone)').val(),
                'SelectedGenderId': $('#@Html.IdFor(u => u.SelectedGender.Id)').val(),
                'SelectedMaritalStatusId': $('#@Html.IdFor(u => u.SelectedMaritalStatus.Id)').val(),
                'SelectedCandidateSourceId': $('#@Html.IdFor(u => u.SelectedCandidateSource.Id)').val(),
                'SelectedCandidateTypeId': $('#@Html.IdFor(u => u.SelectedCandidateType.Id)').val()
                });

                $.ajax({
                    url: this.action,
                    type: 'POST',
                    contentType: 'application/json',
                    data: dataObject
                }).always(function(response) {
                    window.location.href = response.Url;
                });
            }
        });

我在控制器上的操作如下:

 public ActionResult AddCandidate(NewCandidateModel vm, List<HttpPostedFileBase> other, HttpPostedFileBase cv)
    {
//Do stuff here
}

当我执行帖子并开始操作时,HttpPostedFileBase都为NULL。 在我的页面上我也有:

 using (@Html.BeginForm("AddCandidate", "Candidates", FormMethod.Post, new { enctype = "multipart/form-data", id = "frm" }))

我做错了什么? 我忘记了什么?

0 个答案:

没有答案