从StreamContent获取数据到模型

时间:2014-02-19 05:45:40

标签: c# asp.net-mvc-4

在视图中,我有以下代码:

@model Project.Models.DrugEntry

<body>
@using (Html.BeginForm(null, null, FormMethod.Post, new { id = "createDrug", @action = "/api/DrugEntry" }))
{
    @Html.AntiForgeryToken()
    @Html.ValidationSummary(true)

    <fieldset>
        <legend>Add a new Drug Entry</legend>

        <div class="editor-label">
            @Html.LabelFor(model => model.NDC)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.NDC)
            @Html.ValidationMessageFor(model => model.NDC)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Dosage)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Dosage)
            @Html.ValidationMessageFor(model => model.Dosage)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Brand)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Brand)
            @Html.ValidationMessageFor(model => model.Brand)
        </div>

        <div class="editor-label">
            @Html.LabelFor(model => model.Generic)
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.Generic)
            @Html.ValidationMessageFor(model => model.Generic)
        </div>

        <p>
            <input type="submit" value="Add to Database" />
        </p>
    </fieldset>
}
</body>

简单地说,它是四个文本输入框和一个提交按钮,用于创建具有NDC,剂量,品牌和通用名称的DrugEntry。在我的Controller中接收它时,它作为StreamContent对象进入。我已经搜索了所有的SO,但大多数答案使用HttpClient()并需要一个静态网址,我不知道它是什么或为什么它被使用。我可以使用

查看乱码信息
response.Content.ReadAsStringAsync().Result

所以我知道这些信息已经到了,但我如何轻松地提取它呢?

0 个答案:

没有答案