title: Controller Property is not consistent among different HttpGet methods in ASP.NET Core MVC
body: <p>I have a Controller that has two action methods used by a page:</p>
  
  <p>The standard OnGet, that is called, when the page is visited in browser and another method SortData that is called using an anchor tag.</p>
  
  <p>Both of these methods interact with the same property of the controller, but there seem to be like two different object references to the property for each of the methods, because the data inside SortData is inconsistent with the date in OnGet.</p>
  
  <p>Also, if I won't initialize that property inside the Controller's constructor but inside the OnGet method, it will be null inside SortData, even though OnGet has been called first.</p>
  
  <p>My question is how do I get SortData to use the same Property that OnGet uses?</p>
  
  <p>The code looks like this:</p>
  
  <pre><code>public class MyController : Controller
  {
      private MyClass Property {get; set;}
  
      public SearchController()
      {
          Property = new MyClass()
      }
  
      [HttpGet("sortdata")]
      public IActionResult SortData(string sortAttribute)
      {
          Property.SortData(sortAttribute);
          return View("Index", Property);
      }
  
      public IActionResult OnGet([FromQuery]string requeststring)
      {
          ViewData["Message"] = requeststring;
          Property.Datas = requeststring == null ?
              searchService.GetAll() :
              searchService.searchByRequestString(requeststring);
          return View("Index", Property);
      }
  }
  </code></pre>
  
  <p>Of course, the service used in OnGet is being initialized in the Controller as well, but I removed it from the example to keep it rather simple.</p>
  
  <p>So you can see that OnGet modifies Property and returns the Index page. At that page, there is an anchor that calls SortData which also modifies Property. But it is not the same Property as in OnGet, it is still at it's state of initialization. But I want the actual Property to be modified and then return the Index page with sorted data.</p>