【发布时间】:2014-01-08 05:59:44
【问题描述】:
我正在研究 asp.net Web API。我正在尝试保存具有图像数据或文本数据类型属性的复杂类的列表。我有两节课,
问题类
public class Question
{
public int QuestionId { get; set; }
public string Text { get; set; }
public string Type { get; set; }
}
响应类
public class Response
{
public int ResponseId { get; set; }
public int QuestionId { get; set; }
public int UserId { get; set; }
public string ResponseText { get; set; }
}
这是申请表的样子,
--------------------------------------
1, Question Text (Label)
Response (TextBox Control)
--------------------------------------
2, Question Text (Label)
Response (File upload control)
--------------------------------------
3, Question Text (Label)
Response (TextArea)
-------------------------------------
4, Question Text (Label)
Response (Either File upload,Textbox other control)
-------------------------------------
| Submit Answers Button |
-------------------------------------
当用户点击提交答案按钮时,所有页面数据将被发布到 web api 操作。
如果都是简单的文本框,即简单的表单数据,那么我将数据(列表)发布到 web api,就像在 json 中一样,
[{"QuestionId":1,"UserId":321,"ResponseText":"Hello"},{"QuestionId":2,"UserId":321,"ResponseText":"Great"},{"QuestionId":3,"UserId":321,"ResponseText":"Simple"}]
在网络 API 中,
public HttpResponseMessage SubmitAnswers(HttpRequestMessage request,List<Response> responses)
{
....
....
....
}
但在我的情况下,我有多部分表单数据,而且我必须发布多个表单数据,即每个带有响应的问题都被视为一个表单,所以我们如何将多部分表单数据列表发布到 asp。网络 web api 操作。请指导我。
【问题讨论】:
-
你为什么要为此使用 web api 而不是 MVC 控制器操作,这会简单得多。
-
嗯,我需要通过 web api 为 iphone 应用程序提供后端支持,他们的应用程序有问题表格,他们将数据发布到 web api。
标签: c# asp.net asp.net-mvc asp.net-web-api