简体   繁体   中英

C# MVC Access Action Param from controller Initialization

If I have a controller with HTTP POST action with once or several parameters like this:

//[HttpPost]
public ActionResult Ajaxbuscarope(string texto="")
{

}

How could I access to "texto" parameter directly from the controller Initialization...

protected override void Initialize(System.Web.Routing.RequestContext 
requestContext)
{

    var texto=???
}

I can access the Get parameters using this...

var url_with_params=System.Web.HttpContext.Current.Request.Url.AbsoluteUri;

But this is not working with post request with declared parameters

System.Collections.Specialized.NameValueCollection post = System.Web.HttpContext.Current.Request.Form;
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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM