question

LingSteven avatar image
0 Votes"
LingSteven asked Bruce-SqlWork answered

What's the same page lifecycle behavior in asp.net core mvc?

Hi,

I'm porting the old asp.net webform project to asp.net core mvc. The webform page has OnInit method, Load event, Error event. In these event handlers, there're some code logic in it.

I'm new beginner to asp.net core. I do not know to where to place these code.

Please tell me which phase of the asp.net core mvc life cycle that these events correspond to.

Thanks

dotnet-aspnet-core-mvc
· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @LingSteven , according to your said, it seems that you met trouble when migrate webform to asp.net MVC. But basically, MS really has no official document to solve it. Here's a high vote answer in stackoverflow and it indicates webform is poorly adapted to modern web development. If you insist on using similar developing mode, I think you need to using Razor view in dotnet core and composing script to listen to those events and achieve the handler. In other words, when using MVC, frontend focus on the view(show data to users) and the backend only need to combining data and inject to the created model. Here's a simple sample for this scenario. And certainly, you can import Jquery into the view to help you write scripts. If you have further questions, pls feel free to let us know. Thanks for you reply in advance.


1 Vote 1 ·

1 Answer

Bruce-SqlWork avatar image
0 Votes"
Bruce-SqlWork answered

Webforms built a control tree and fired events, for example oninint after the tree built, on load after tree built and postback data applied, etc. finally onrender, when the tree was converted to html.

Mvc is a different model. An action is called to build a view model. Then a view is called to render the model. The view is a template engine, so there are no events. The post data is passed to the action rather than being applied to a control tree.

Mvc has request pipeline with event filters. Pre action, post action, etc.

The action controller can catch errors via an exception handler, otherwise an error action is called. You can also override the default error action.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.