在表单数据C#中使用视图模型的上传文件的Swagger attribures

时间:2018-06-01 06:36:02

标签: c# http controller swagger swagger-ui

我试图编写一个HTTP控制器方法来接收文件和一些额外的数据。还有很多其他数据,所以我需要使用视图模型而不是单独的参数。

我尝试在模型中添加一个文件。像这样:

import React from 'react';
import Adapter from 'enzyme-adapter-react-16';

import ProjectStore from './projectStore.js';

describe('<ProjectStore />', () => {
  it('should return loading count', () => {
    ProjectStore.setLodingCount(2);
    expect(ProjectStore.lodingCount).toEqual(2);
  });
});

并尝试单独传递文件:

public class ViewModel
{
    public string SomeField { get; set; }
    public HttpPostedFile File { get; set; }
}

public async Task<IHttpActionResult> Create(ViewModel model)

但在这两种情况下,我无法通过Swagger UI上传此文件。在第一种情况下,&#34;文件&#34;字段从视图模型中消失,而在第二个字段中没有带有上载文件按钮的字段。告诉我,需要为此方法配置什么样的Swagger注释才能执行此操作?

P上。 S.如果我这样做,它会起作用public class ViewModel { public string SomeField { get; set; } } public async Task<IHttpActionResult> Create(ViewModel model, HttpPostedFile file) 。但这不是我的解决方案,我想将其他数据作为表单数据传递。

0 个答案:

没有答案