سؤال

I used to develop with ColdFusion for a while, but then left the web development arena for a while. I'm back, now, and have been hired as an intermediate (right above entry)-level web developer. My workplace is using MVC 4, but is not using the Razor view engine. The two MVC 4 books that I've purchased (as well as the huge number of tutorials and blogs out there) only discuss using Razor- which I AM using in my self-study, but I need to understand how it works when NOT using the Razor engine.

When using the ASPX view engine, how do you go about using it? Does it work like a normal ASPX page, where I place my ASP.NET controls on the page and then reference them with the code-behind in C#? Only, rather than using ASP.NET controls, I'm using HtmlHelper methods instead? Keep in mind, I'm not asking about the basic format of using <% %> instead of <@, because most of that was covered here: http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx. I fail to understand how traffic will get routed to those ASPX pages through my basic HomeController (which just has a few ActionResult() methods, nothing large).

I can elaborate more, if need be.

هل كانت مفيدة؟

المحلول

All MVC view pages follow the same life cycle regardless of the view engine:

  1. Routing - The request is mapped to an action method (using request data like URL, querystring, session, etc)
  2. Controller - A controller is created for the matching action method. It's populated with all the environment, request, and session data
  3. Action - The matching action method is called
  4. Result - The ActionResult returned by the action method is executed. For a view result, this means: 1) The view engine locates a matching view name, 2) the matching view is instantiated with any model data returned by the action method, 3) the view is processed by the view engine.

That means a WebForms view will be executed by the MVC WebForms view engine, not by the ASP.NET WebForms system. The view engine will perform some basic parsing to add the data from your model to your view (as specified with <%%>).

Also, FYI you can even mix view engines in a single project (requires some setup).

نصائح أخرى

Look at

The ethos of MVC is to get rid of code behind so the old way of drag drop onto the designer and manipulating the control from code behind has become somewhat out dated or redundant. If you are already using HTML5 helpers .. I would continue to do so.

This is purely a personal view ... but I would make a case for using Razor.

Edit: You pass the model to the view ... the model holds the data.

If you are using ASP.NET MVC then forget about code behind. As for as the view engines are concerned you can go razor or aspx way means the syntax you can use on your views is either razor or aspx. Routing will not be affected by your choice of view engine.(It will behave same whether you choose razor view engine or aspx. And NO aspx views does not behave like normal aspx webform, no code behind no viewstate etc Here is a good comparison of ASP.NET and ASP.NET MVC and Here is comparison of different view engines.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top