how is controller context done in 4.0

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
6 years ago
how is this to be done in version 4.0


public int GetCurrentId()
        {

            if (ControllerContext == null)
            {
                var context = new ControllerContext(System.Web.HttpContext.Current.Request.RequestContext, this);
                ControllerContext = context;
            }
            var Id = Convert.ToInt32(ControllerContext.RequestContext.RouteData.Values["id"]);
            return Id;
        }



Anyone?
6 years ago
I've done something like this:

            var httpAccessor = EngineContext.Current.Resolve<IHttpContextAccessor>();

            var qs = httpAccessor.HttpContext.Request.QueryString;

             var parsedQueryString = Microsoft.AspNetCore.WebUtilities.QueryHelpers.ParseQuery(qs.Value);
             var id = parsedQueryString["id"];


This gets the QueryString in the qs variable.  You can then parse the query string and get the value of ID in the id variable.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.