小编lak*_*ide的帖子

使用 ajax 在 MVC Core 中发布包含 IFormFile 属性的视图模型

我正在尝试使用 jquery AJAX 帖子在 MVC 核心中发布一个简单的视图模型,但是模型上的 IFormFile 属性似乎为空。

我有以下视图模型:

    [Required]
    public IFormFile File { get; set; }

    [Required]
    [Display(Name = "Owner")]
    public int DocumentOwner { get; set; }

    [Required]
    [Display(Name = "Document Type")]
    public int DocumentTypeId { get; set; }
Run Code Online (Sandbox Code Playgroud)

然后我在视图底部的脚本中使用 jQuery ajax 帖子:

$("form").submit(function (e) {
    e.preventDefault();

    var model = $('form').serialize();

    $.ajax({
        type: "POST",
        url: "/Client/AddDocument",
        contentType: false,
        processData: false,
        data: model,
        success: function (message) {
            alert(message);
        },
        error: function () {
            alert("There was error uploading files!");
        }
    }); …
Run Code Online (Sandbox Code Playgroud)

ajax asp.net-mvc jquery asp.net-core

3
推荐指数
1
解决办法
9741
查看次数

标签 统计

ajax ×1

asp.net-core ×1

asp.net-mvc ×1

jquery ×1