1

I am new to ASP.net MVC .

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

Does MVC Supports events,if so what events are supported.

Please Clarify me about this..

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Sai Avinash
  • 4,683
  • 17
  • 58
  • 96
  • what do yopu want do in the page_load? possible duplicate http://stackoverflow.com/questions/10090934/mvc-equivalent-of-page-load – lordkain Sep 03 '13 at 11:05
  • 2
    No - ASP.NET MVC doesn't have a page lifecycle like classic Webforms has. – marc_s Sep 03 '13 at 11:11
  • 1
    There is no such thing as a "page" in the conventional sense in MVC. Your "page" that the end user sees is made up of a View, a controller and optionally a model. There is no server-side 'page' per se. The logic that you would put in page_load in webForms may go in the corresponding controller actions, but the clean separation of concerns in MVC means there may actually be a better place for this behaviour to live anyway. – LDJ Sep 03 '13 at 11:11

1 Answers1

5

,i was going through a tutorial on MVC, where they used Page_Load event which is same as in Web forms.

You could forget about this tutorial. Things like events and Page_Load are not used in an ASP.NET MVC application. You were probably looking at a tutorial about classic WebForms.

You may get started with ASP.NET MVC at the official page: http://asp.net/mvc

Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • Hi Darin..This is the page where i found it..http://weblogs.asp.net/scottgu/archive/2007/11/13/asp-net-mvc-framework-part-1.aspx – Sai Avinash Sep 03 '13 at 11:09
  • @Avinash I see practically no mention of `Page_Load` in Scott's post, only in the comments. – vcsjones Sep 03 '13 at 11:11
  • 1
    @Avinash, where did you even see Page_Load in this tutorial? If you are using the WebForms view engine, bear in mind that you don't even have a code behind file as in classic WebForms application. There's no even a notion of Page in ASP.NET MVC. There are Models, Views and Controllers. Bear in mind that this tutorial was written before ASP.NET MVC was released, so there might be some inconsistencies. – Darin Dimitrov Sep 03 '13 at 11:12
  • @DarinDimitrov : In the article, see the sub heading , rendering Approach 2 , using Server side controls. i was even suprised to see server controls being used. can you please clarify me on this..ia m pretty much confused – Sai Avinash Sep 03 '13 at 11:15
  • 1
    Yeap, I saw it. This is wrong. As I said this article was written before the actual ASP.NET MVC was released. There's no such thing as Page_Load. I would recommend you reading the official tutorials to get started: http://asp.net/mvc – Darin Dimitrov Sep 03 '13 at 11:16
  • @DarinDimitrov - So we should not use server side controls ,Code behind or any events ..Am i correct ? – Sai Avinash Sep 03 '13 at 11:17
  • 1
    Yes, you are absolutely correct. Forget about any server side controls, code behind and events. – Darin Dimitrov Sep 03 '13 at 11:19
  • @Darin :Thank You.this question may be off topic, i would like to know what controls can be used for data binding ,instead of grid views as in case of classic web forms , i am very strong user of grid views. I am confused to what control could fit in for grid view incase of MVC.. – Sai Avinash Sep 03 '13 at 11:23
  • 1
    You could use the built-in WebGrid helper. Or use third party helpers such as KendoUI which offers lots of available widgets. – Darin Dimitrov Sep 03 '13 at 11:23
  • One more doubt Darin , i think we can not even use ASP.net Ajax for MVC, how to deal with Ajax in MVC ? Do we need to write our own Ajax calls ? – Sai Avinash Sep 03 '13 at 11:26
  • 1
    Of course that you have to write your own calls. jQuery is a pretty popular javascript framework that you could use for this task. – Darin Dimitrov Sep 03 '13 at 11:30