Asp.net MVC is a problem with the custom razorviewengine to implement free topic switching!

Source: Internet
Author: User

I have been entangled in this problem for several days. Although I haven't fully understood it, I just made some progress. I will record it. If you have any detailed answers, please don't hesitate to give me some advice.

Opening part:Those familiar with MVC understand that the controller and the action in it will correspond to the files in views by default, so that the content in the Controller will be transmitted to the page and displayed on the browser. For example, it is the structure of the default views in the original mvc3 project.

 

If we want to create another set of page themes and implement a free switch with the built-in style above, we simply need to follow the directory structure below views and then perform a parallel set with it. The directory structure is as follows:

We added the themes file under views, which is divided into default and green. The default file is the original file, and the Green file is another set of style Files written by ourselves.

Next, we will use the razorviewengine class written in the title of this article. inherit from the razorviewengine class and use the custom engine to switch between the default and green themes. (Find the specific operation in the garden. I have written many articles. I am not so embarrassed. The following mainly describes my own problems)

Problem:In default and green, I put content to write CSS files and JS files. Because the two themes are different, separate calls here is also the most intuitive solution. However, the problem occurs. The custom view engine can smoothly switch between default and green to load the account, home, and shared folders, however, when the Page Link label in the content folder loads the style, 404 appears.

In the debugging window of chrome F12, the status after the file in the request content is canceled.

I found a lot of information that I was still not satisfied with. One answer was that the reason for Cross-site access was always confused.

However, after many attempts, I finally found that the content folder is not in the correct position! You just need to take it out and call it smoothly.

Finally, I put the conent under the project root directory, and set up default and green respectively to differentiate different style files. In this way, the freely switching feature of the topic can be completed.

The function is complete, but Why cannot the content be stored in views managed by the view engine *_*

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.