What is an MVC framework and why is it necessary/useful?

前端 未结 9 774
自闭症患者
自闭症患者 2021-02-02 03:01

I know that an MVC framework allows you to separate business logic, data base access and presentation, but why do we need a framework to do this.

Can\'t we just keep ou

相关标签:
9条回答
  • 2021-02-02 03:20

    MVC stands for “MODEL” “VIEW” “CONTROLLER”. ASP.NET MVC is an architecture to develop ASP.NET web applications in a different manner than the traditional ASP.NET web development. Web applications developed with ASP.NET MVC are even more SEO (Search Engine) friendly. Developing ASP.NET MVC application requires Microsoft .NET Framework 3.5 or higher.

    Model:

    • MVC model is basically a C# or VB.NET class.
    • A model is accessible by both controller and view.
    • A model can be used to pass data from Controller to view.
    • A view can use model to display data in page.

    View:

    • View is an ASPX page without having a code behind file.
    • All page specific HTML generation and formatting can be done inside view.
    • One can use Inline code (server tags ) to develop dynamic pages.
    • A request to view (ASPX page) can be made only from a controller’s action method

    Controller:

    • Controller is basically a C# or VB.NET class which inherits system.mvc.controller.
    • Controller is a heart of the entire MVC architecture.
    • Inside Controller’s class action methods can be implemented which are responsible for responding to browser OR calling views.
    • Controller can access and use model class to pass data to views
    • Controller uses ViewData to pass any data to view.

    MVC Basic Architecture

    0 讨论(0)
  • 2021-02-02 03:23

    You can of course approach it yourself by segregating your classes. A framework supplies common scaffolding that you wouldn't have to build yourself. But it will also impose some structure on your code. You'll have to evaluate whether the framework helps more than it hurts.

    0 讨论(0)
  • 2021-02-02 03:24

    In my opinion the thing you are talking about is the MVC pattern and not a specific framework. Of course you can go and keep all your classes within one project and still use the MVC pattern, as you have all your UI code in the views, the logic in the controllers, ...

    A MVC framework on the other hand makes it easier for you to use this pattern. It may provide some base classes for controllers and a mechanism for the communication between view and controller.

    I don't know if you are familiar with ASP.NET MVC. The framework itself is very small, but it helps you developing an application with the MVC pattern, as you don't have do think about the previously decribed areas...

    Hope this helps

    0 讨论(0)
  • 2021-02-02 03:24

    You are correct, there are strategies that you can implement to help with separation of concerns without using MVC.

    Microsoft's ASP.NET MVC framework is one strategy that can be employed, and that is what I think you are asking about. This MVC framework makes such separation of concerns easy.

    The other major advantage of MVC is testability - (depends on whether you believe in unit testing - I do).
    The MVC framework ensures that all orchestration logic is on your controllers and through the FormControls collection allows full unit testing of all aspects of your application except for how it is presented.

    As the MS MVC framework encourages adherence to common rules and structure of the application which should lead to greater maintainability.

    The major downside of MVC is the code-in-front code weaving required for presentation, but this can be easily overcome.

    0 讨论(0)
  • 2021-02-02 03:35

    MVC is a code organization architecture style to organize your code-logic in a meaningful way for web applications. As a programmer I have almost puked when I have inherited other people's code when their code logic is all over the place and following their web application code turns into following a rabbit down the gutter hole. Why MVC? hmm.. well why should I use a filing cabinet or folders to organize my plethora of paper and not just have my papers stashed in a large pile and have others figure how they connect to each other. It increases code readability. With MVC it becomes very easy to follow code logic since you are following standard structure for a web application. Business logic is separated out from UI. Easier to delegate work decouple work on a project.

    0 讨论(0)
  • 2021-02-02 03:37

    MVC and framework is a different thing. MVC is just an architectural pattern, which can be applied with any project, with or without framework.

    So you don't need a framework to do this. You can separate them by yourself. :)

    0 讨论(0)
提交回复
热议问题