Is ASP.NET MVC 3 ready for business applications

2019-02-12 00:49发布

问题:

I have to decide about a new big business application we will develop in the coming years, the question is if we should start using MVC 3 or web forms.

This was discussed already here in SO but I have seen the question: ASP.NET MVC ready for business applications (integrating 3rd party controls/components)? was asked in 2008 and now many things could have changed.

My main concern is having heard MVC is good for rendering content like grids or lists and not so good for data input and user interaction.

Our application will have a lot of controls in which users are entering data and working with lists and text boxes, check boxes and so on.

is everything absolutely possible also in MVC or the classic Webforms and view state model would be more appropriate?

thanks.

回答1:

I have used every single version of WebForms since 1.0 beta and MVC 1, 2 and 3 and believe that MVC is definitely ready for production use.

You must take into consideration that the development approach of the 2 is quite different:

MVC requires that you learn more low level details of the basic web technologies: HTML, CSS, JS, HTTP, (which I believe you should anyway if they are not in your skill set yet).

WebForms tries to abstract most of it and can be considered more productive for throwing together some simple pages. But it is a leaky abstraction and the lack of control may frustrate you as you grow more proficient - easier in the beginning if you are new to web development; harder to bend as you gain experience. The productivity gains start to disappear when the pages become more complex. The abstraction is more likely to cause performance problems and undermines the ability to automate testing of your pages (both unit and UI level testing with Selenium or equivalent tools).

Example 1: in MVC you most likely will need to understand how form fields are processed to compose a POST over HTTP with application/form-url-encoded, otherwise you may struggle with model binding. In WebForms you can build big applications without ever worrying with that.

Example 2: In MVC you need to manage most of your page state across requests. In WebForms it's easy have the framework do it for you.

MVC applications tend to rely more on client side javascript components for having reusable widgets, binding JSON data for example. WebForms encourages the use of server side controls since they integrate nicely into the framework state management facilities.

Unlike other people I don't believe in saying that MVC is strictly more productive than WebForms. Don't underestimate the WebForms ability to deliver data driven business applications quickly. Having managed a lot of people using both, my opinion is that MVC requires more skilled programmers to become more productive. But if that is your case you will likely find that MVC is a more enjoyable and powerful platform in those skilled hands.



回答2:

Is ASP.NET MVC 3 ready for business applications

is everything absolutely possible also in MVC

In my humble opinion; Absolutely 100% yes. In fact, I submit that the MVC framework is lightyears ahead of WebForms in both functionality and productivity.



回答3:

Yes, ASP.NET MVC 3 Razor is definitely ready for business applications. I am building a large, enterprise-class web application in MVC 3 Razor C# and the more complexity I throw at MVC and the Entity Framewor, the better they handle it. Let me give you a code example. Lets say we want to create a dynamic table that mixes HTML with Razor C# code and data. This is no small task using web forms and ASP.NET Web controls

<table>          
    <thead>
        <tr>
            <td>Date</td>
            <td>Name</td>
            <td>Price</td>
            <td>Quantity</td>
            <td>Shipper</td>
        </tr>
    </thead>
    @foreach (eStore.Models.Product p in Model.Products)
    {
        <tr>
            <td>@Html.Hidden("Date", p.Date.ToString())
                @Html.Hidden("productId", p.ProductId)
            <td><input type="submit" name="submitButton" value="@p.Name"/></td>
            <td>@Html.Label("Price", p.Price)</td>
            <td>@Html.Label("Quantity", p.Quantity)</td>
            <td>@Html.Label("Shipper", p.Shipper)</td>
        </tr>
    }
</table>

I have created a dynamic table containing a list of products with a button that can access more information on each product in the list by productId. This required a minimal amount of code and effort. The code is clear, understandable and easy to edit. Now imagine what would be required with conventional web forms and web controls to perform the same task.

There is a learning curve with MVC 3 but it is in my opinion well worth it.