IModelBinder:访问请求的原始数据

IModelBinder: access the raw data of the request

我正在尝试查看通过 IModelBinder 界面在 POST 中发送的文本。我有类似的东西:

    public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
    {
        if (controllerContext.HttpContext.Request.ContentType.ToLowerInvariant().StartsWith("my special content type"))
        {
            var data = ???

...在哪里???应该是 POST 中发送的文本。它应该是一堆文本(我认为),但我不知道如何访问它。谁能赐教一下?

好的,根据@ScottRickman 的建议,我查看了 上的文章,了解了如何将其应用于 IModelBinder:

public object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
{
    if (controllerContext.HttpContext.Request.ContentType.ToLowerInvariant().StartsWith("my special content type"))
    {
        var body = GetBody(controllerContext.HttpContext.Request);
        var model = MyCustomConverter.Deserialize(body, bindingContext.ModelType);
        return model;
    }
}

private static string GetBody(HttpRequestBase request)
{
    var inputStream = request.InputStream;
    inputStream.Position = 0;

    using (var reader = new StreamReader(inputStream))
    {
        var body = reader.ReadToEnd();
        return body;
    }
}

这完全符合预期。