26, the introduction of ASP. NET MVC to proficiency--background management area and separation, JS compression, CSS, jquery extension

Source: Internet
Author: User
Tags css zen garden

Catalog: ASP. NET MVC4 get started to Master Series catalog summary

Have a period of time not updated blog, recently busy two things:1, reading, learning ... 2, for the company's annual program to prepare for a long time did not practice double-cut sticks, inevitably unfamiliar, so now cramming. The recent weather in Shenzhen is abnormal, many people have a cold, I also become one of them, everyone pay attention to the body ...

In this article, let me briefly describe some of the assorted techniques that will be used in the next project.

Area and Separation

I havebriefly explained the separation of areas in the introduction of ASP. NETMVC to proficient --mvc- routing .

1. Right-clickWebproject, "Add"--"zone", the area name, which we named hereAdmin, after the creation is completeWebproject, there will be an extraareasfolders,areasthe folder below will have the one we just createdAdminfolder, inAdminThe folder contains a completeMVCproject directory, here, we don't want to put the controller inWebProject, so delete theControllersand theModelsfolder.

2, the new Class library project Web.Logic.Admin, this class library project we come as the background system of the area, the Admin folder in the AdminAreaRegistration.cs Copy it and then put the file into the Web.Logic.Admin Project and modify the file namespace.

3. Add the following references to the Web.Logic.Admin Project

4.Web Project Add reference to Web.Logic.Admin Project

5. new membercontroller class in Web.Logic.Admin project

     Public class Membercontroller:controller    {        [httpget]        public  actionresult Index ()        {            return  View ();        }    }

6. In the Web project, under the areas/admin/views/member directory, add the view index.cshtml

@{    viewbag.title = "Index";} < H2 > Index</h2> Test

7, in the browser input address http://localhost:10757/Admin/Member/, the operation results are as follows:

JS Compression and merging

In the Web project, in the BundleConfig.cs file Registerbundles method, add the following code:

Bundles. ADD (NewScriptbundle ("~/mvcajax"). Include ("~/scripts/jquery-1.8.2.min.js","~/scripts/jquery.unobtrusive-ajax.min.js",
"~/scripts/jquery.validate.min.js","~/scripts/jquery.validate.unobtrusive.min.js","~/scripts/jquery.msgprocess.js")); Bundletable.enableoptimizations=true;

The jquery.msgProcess.js in this is my custom.

View Call Code:

    @Scripts. Render ("~/mvcajax")

About compression and consolidation I have a more detailed description in 21, the introduction of ASP. NET MVC to proficient--asp.net MVC4 optimization, here is just a brief mention, no longer repeat it.


I find many. NET Web developers front-end this piece is very weak, although many companies have specialized front-end engineers and artists, but the necessary knowledge of the front-end is helpful.

Learning CSS, I recommend an ebook, "CSS Zen garden", we do not require a deep understanding of CSS, to understand most of the CSS code, copy some of the existing CSS style, you will modify its style.

Here, let me briefly describe the CSS styles that we have used very frequently in our development.

We often encounter such requirements, depending on the conditions, dynamically control the interface of an element of the hidden and display, we usually consider the following two ways to achieve:

Set element Hide

    • Display:none;
    • Visibility:hidden;

Display: does not affect the CSS layout, display is actually a floating feature of the set element.

Visibility: Affects the CSS layout, which can have a certain effect on performance, because it causes the HTML interface to reflow. When set to hidden, the element is hidden, but it still occupies its original position, and the visibility property is the hidden element but keeps the element floating.


jquery, also commonly used in our web project development, recommends an ebook, "Sharp jquery."

To unify the AJAX data approach, I first add a unified Ajax format class to the model project Ajaxmsgmodel

    ///<summary>    ///Unified AJAX Format Class    ///</summary>Public class Ajaxmsgmodel {public string Msg {get; set;} ///<summary>        ///Ok,error        ///</summary>Public string Statu {get; set;}        public string Backurl {get; set;} ///<summary>        ///Data Objects        ///</summary>Public object Data {get; set;} }

Then in the Web project scripts directory to create a new JS file Jquery.msgProcess.js, and then add a jquery extension method, as for the use of jquery extension method, if not clear, please check the information directly. I always like to pay attention to, copy over, and then figure out, and finally revise their own, the typical lazy practice.

(function($) {$.extend ($, {procajaxdata:function(data,funcsuc,funcerr) {if(!data. Statu) {return; }            Switch(data. Statu) { Case"OK": Alert ("OK:" +data.                    MSG); if(FUNCSUC) funcsuc (data);  Break;  Case"ERROR": Alert ("ERROR:" +data.                    MSG); if(Funcerr) funcerr (data);  Break; }        }    });} (JQuery));

Called In view

    <script type= "Text/javascript" >        function  Success (jsondata) {            function () { window.location = jsondata.backurl;});        }     </script>
Jquery Easyui

About Easyui, we stand on a user's point of view, is really more its name as easy. About its use can go to http://www.jeasyui.net/study.

Select a version, the source code and documents to download, the latest version, the document is generally in English. After downloading, there is a lot of HTML demo. There are ready to directly copy over, online about Easyui sample code countless, or that sentence, copy over, see understand, will be modified, OK, not recommended in not learning a new framework, the framework of the document from the beginning to the end, the real work, there are very few companies will have so much free time to us, So we are generally used first, there is need, and then in-depth.

26, the introduction of ASP. NET MVC to proficiency--background management area and separation, JS compression, CSS, jquery extension

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.