Coder Social home page Coder Social logo

asp.net-mvc-component's Introduction

ASP.NET MVC Component

A component-oriented project template for Visual Studio, based on the template for ASP.NET MVC.

The Problem

If you have encountered any of these problems, then probably you would want to structure your files in the project in a different way:

  • Controllers grow indefinitely
  • Models, view, and controllers are coupled and typically you would want to fidn the model fo the view and maybe change it. But thsi change should be propagated from the controller. In a big project this can get messy.
  • You have a lot of views (partial counts as well) and it becomes hard to keep track of them

The Solution

A simple solution to this growing mess could be restructing the solution. Instead of keeping models, views, and controllers separated, we should keep them close to each other, because they are related.

In this template you use the same elements (i.e., models, views, and controllers), but structured in a different way. Instead of working with raw controllers, we have two options: PageController and ComponentController.

The template provides a "root" folder, called Pages. You create a separate folder for each general page you have in your application: f.x., Home, Account, Statistics. Sometimes you need to share elements across pages and you can use the special page, called Shared. Each page can contain PageControllers, views and components. For each component you should also create a separate folder, f.x. NavigationBar, SearchMenu, ProfileWatch. If you want to share components between pages, you should place them in the Shared folder instead.

Project structure

Pages

Pages correspond to your "raw" controllers. One page can contain many subpages, i.e. different action methods. The base class for pages is PageController. Each PageController contains a method, called Index(). You can have other methods as well, but this one is requried.

You can have pages without an explicit controller, i.e. only with a view. In this case the raw PageController will be used.

Components

Components are created using the base class ComponentController, which define a must-to-have method Render(). Components are rendered using Html.RenderPartial() helper which is wrapped in a method, called Html.Component("Name").

You can have components without an explicit controller, i.e. only with a view. In this case the raw ComponentController will be used.

How to install

You can open the solution using Visual Studio and then from the menu, you can choose Export Template...

Feedback

Please, do shre your thoughts, ideas, and questions. Send me a pull request if you want to change anything.

asp.net-mvc-component's People

Contributors

boyanio avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.