Ashutosh Kushawaha
Ashutosh Kushawaha

Reputation: 791

if asp.net mvc doesnot support page load event then what should we do for page laod event in mvc

I am new to ASP.NET MVC .

To start learning on MVC, I was going through a tutorial on MVC, where they used the Page_Load event which is same as in Web forms.

Does MVC support events, and if so what events are supported?

If ASP.NET MVC does not support Page_Load event, then what is the alternative?

Upvotes: 1

Views: 3596

Answers (2)

Saket Kumar
Saket Kumar

Reputation: 4835

One thing that i was told before learning MVC was, 'Just forget everything about Webforms. It's old, and doesn't support separation actually.' Don't think about asp.Net webforms while learning MVC. MVC has a different life cycle. An answer to your question is, MVC doesn't support Page_Load or any event, and it all depends on what you want to implement. Here are few tips:

1.) If you want to implement something before View (UI or html page) is rendered, you can write logic in controller before returning the View.

2.) If you want to implement something in the process of rendering page, you can use razor markups. It is quite easy to use razor.

3.) If you want to implement something after Page has been totally rendered, you can use jQuery's document.Ready().

You can start learning MVC here: http://asp.net/mvc

Upvotes: 4

Ishtiaq
Ishtiaq

Reputation: 1058

You should use Javascript/Jquery for event handling in MVC application. You may be use document.Ready() event handler to trigger the page load event and then handle your logic using javascript/jquery.

Upvotes: 0

Related Questions