如果我有一个带有HTTP POST操作的控制器,有一个或几个参数,如下所示:
//[HttpPost]
public ActionResult Ajaxbuscarope(string texto="")
{
}
我怎样才能访问" texto"参数直接来自控制器初始化...
protected override void Initialize(System.Web.Routing.RequestContext
requestContext)
{
var texto=???
}
我可以使用这个...
访问Get参数var url_with_params=System.Web.HttpContext.Current.Request.Url.AbsoluteUri;
但这不适用于声明参数的发布请求
System.Collections.Specialized.NameValueCollection post = System.Web.HttpContext.Current.Request.Form;
答案 0 :(得分:0)
HttpRequest request = HttpContext.Current.Request;
request.InputStream.Seek(0, SeekOrigin.Begin);
var reader = new StreamReader(request.InputStream);
var requestFromPost = Encoding.Default.GetString(HttpContext.Current.Request.BinaryRead(HttpContext.Current.Request.TotalBytes));
//this is very important to have the parameters available in the action
request.InputStream.Seek(0, SeekOrigin.Begin);