“ HttpRequestBase”不包含“正文”的定义

时间:2019-12-03 04:01:18

标签: c# asp.net-mvc httprequest

this is error snippet

我试图从视图到控制器端获取数据表搜索值,但我的控制器返回错误:

  

'HttpRequestBase'不包含'Body'的定义,也没有可访问的方法'Body'

这是我的控制器代码段:

public ActionResult EditCustomer(int id)
{
    string requestData = "";

    using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
    {
        requestData = reader.ReadToEnd();
    }

    NameValueCollection data = HttpUtility.ParseQueryString(requestData);
    string Search = Convert.ToString(Request["search[value]"]);     
}

1 个答案:

答案 0 :(得分:1)

尝试以下代码(顺便说一句,我看不到您如何使用data变量?但这不是问题的对象)

public ActionResult EditCustomer(int id)
{
    string requestData = "";
    using (Stream iStream = Request.InputStream)
    {
        using (StreamReader reader = new StreamReader(iStream, Encoding.UTF8))   //you should use   Request.ContentEncoding
        {
            requestData = reader.ReadToEnd();
        }
    }
    NameValueCollection data = HttpUtility.ParseQueryString(requestData);
    string Search = Convert.ToString(Request["search[value]"]);     
}