Pageload event in MVC

Thyag Ann picture Thyag Ann · Aug 2, 2013 · Viewed 21.4k times · Source

I have webform code as below.I need to have this in mvc.. What to use to initialize objext in pageload event in asp.net mvc

  protected void Page_Load(object sender, EventArgs e)
    {
        Control ctrl = (Control)Session["ctrl"];
        PrintHelper.PrintWebControl(ctrl);
    }

Answer

anaximander picture anaximander · Aug 2, 2013

ASP.NET MVC doesn't work on events like ASP classic; there's no "pageload event". Your controller methods correspond to requests sent to the server. You'll need to build the equivalent control in HTML, and then use a form to HTTP POST the data to the server, where it is handled by a controller method.