ASP. net mvc and code hidden files

Source: Internet
Author: User

The ASP. net mvc community discussed whether to hide files in the code when using WebFormsViewEngine, and whether this is an advantage or disadvantage or even a problem.

ASP. net mvc still uses WebFormsViewEngine by default. When Visual Studio is used to add a WebForms View to the ASP. net mvc application, a code hidden file and a designer file are automatically added. Many people think that code hidden files have been deprecated and their usage is confusing, because developers tend to use views like traditional ASP. NET Web forms.
Steve Smith further demonstrated the disadvantages of the ASP. net mvc Codebehind file because they tempted developers to add logic to the view, and the view should be "dumb" in design ":

Hiding files in code is a temptation. Not familiar with ASP. net mvc (ASP. net mvc has not been released yet in less than a year. But developers with Web forms development background (MOST) always have a tendency to write code into hidden code files. This makes the logic in the view difficult to test. The worst possibility is that the logic contained in the hidden code file directly calls the database or web service, and thus completely bypasses the separation of the model from the view.
Steve explains that hiding a file in code is a bad but essential thing in some situations. For example, you want to reference a Model in a strongly typed view ). Some writers think that the hidden code page can also be used to store some view logic, while other methods may confuse the ASPX file. Last but not least, they want to get support for smart tip technology on the ASPX file. As for the first question, Tim Barcz demonstrated how to use ViewData without code to hide and use strong ViewData, and replace the C # Or VB notation by combining generic CLR Notation:

Inherits = "System. Web. Mvc. ViewPage '1 [[ABCCompany. MVC. Web. Models. LoginData, ABCCompany. MVC. Web]"

CLR notation specifies the number of generic parameters after single quotes, followed by parameters and Assembly containing parameter types.
 
Luis Abreu does not agree with Steve's usage and responds in the post. He said, "You cannot delete the hidden code file to make up for the deficiency of A 'nonconformity 'programmer," because the logic can still be placed in the script block of the ASPX file. Luis does not agree with the general viewpoint of the "dumb" view. He believes that the view may be mixed with the "show-related code", and the code should be put in a hidden code file rather than in the Controller or written directly in the ASPX file, this will destroy the clear separation between the tag and the code.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.