As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
With the release of ASP.NET MVC 3, I am wondering what are the major reasons (killer features) we should upgrade our app to MVC3.
Our app is currently in MVC2 using:
Ninject & Ninject.Web for IoC,
Linq to Sql
jQuery (no ASP.NET Ajax)
flot charts.
MVC Contrib
Custom REST (through dynamic WCF no XML config files)
We do not use ASP.NET charts or EF etc.
Is there any real compelling reason we should upgrade to ASP.NET MVC 3?
Here's a few additional features in ASP.NET MVC 3
Razor view engine (Widely seen as a vast improvement on the previous ASPX view engine)
Improved model validation with unobtrusive JavaScript and jQuery support. Including new remote validation amoungst others
Partial page output caching.
Dependency Injection Improvements, new IDependencyResolver`
More imporvements and details can be found at ASP.NET MVC site along with Scott Guthrie's anouncment
But only you can evaluate whether you should upgrade or not for your specific project.
It should be noted (as Robert Koritnik commented) that MVC 3 requires .NET 4.
No more custom controller factory! This will apply to you. They wrote a new IDependencyResolver that you implement and DependencyResolver.SetResolver(...). Your IoC will go through out the application.
http://weblogs.asp.net/shijuvarghese/archive/2011/01/21/dependency-injection-in-asp-net-mvc-3-using-dependencyresolver-and-controlleractivator.aspx
The main two reasons we're about to upgrade are:
1) The ability to control HTML validation on a per textbox basis rather than on a whole page- this means we can allow the users to enter HTML into some textboxes on a page, rather than having to control it at the page level.
2) Remote validation - much less ajax for us to write!
1 Razor
2 Razor Intellisense within Visual Studio
3 Partial Page Output Caching
4 Validation and JavaScript/AJAX improvements
The Razor View Engine will make your view code nicer.
More details here
Apart from all the answers there are few other reason for adopting MVC 3
Unobtrusive Javascript
Global Action Filters
Custom Validation attributes and Self validation
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I've been using MVC for over a year now, and I like it alot. I've heard of Knockout.js. How is the comparison between these two? Which is better?
MVC seems to have reached its maturity with MVC5, with alot of support.
I do not see knockout.js as well supported. There examples on their site do not even work in Firefox. However, I can see the potential of this since it is written in javascript, client-side, and possibly faster since its client-side, like ajax.
What are the advantages of Model-view-controller vs Model-View-View-Controller?
You should not be comparing Knockout.js to Asp.NET MVC. The only similarities are that they both use the same Model-View-Controller pattern.
Knockout.js:
Knockout is a standalone JavaScript implementation of the Model-View-ViewModel pattern with templates. The underlying principles are therefore:
a clear separation between domain data, view components and data to be displayed
the presence of a clearly defined layer of specialized code to manage the relationships between the view components
The latter leverages the native event management features of the JavaScript language.
Asp.NET MVC:
ASP.NET MVC allows you to build a web application as a composition of three roles: Model, View and Controller.
A model represents the state of a particular aspect of the application. A controller handles interactions and updates the model to reflect a change in state of the application, and then passes information to the view. A view accepts necessary information from the controller and renders a user interface to display that information.
As you can see Knockout.js is an MVC implementation for JavaScript while Asp.Net MVC is an MVC implementation for a complete web application from front end to server. These technologies can even (and very often) be used together to build well structured applications on both the front end and the back end.
You are comparing apples and oranges...
Since you are now familiar with ASP.Net MVC (and the MVC design pattern in general), it is time to take the next step and use a JavaScript MVC framework WITH it.
There are many choices, some popular ones include Knockout.js, AngularJS, Backbone.js, Ember.js, and many more. The site TodoMVC will give you a flavor of what is out there.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I have been working as WinForm (C#) Developer since Aug 2010. Now, I am planning to migrate into Asp.net MVC (C#). I have been learning MVC with http://www.asp.net/mvc for last 10 days. But I found that it only emphasizes on razor technology over ASPX. I just want to clear doubt that Do you use Razor technology in your MVC Project over ASPX. Please also mention other stuff I should learn (or from where) to be an Asp.net MVC Developer (Good & Employed).
Thank you,
Aman
Welcome to StackOverflow (SO)
Razor is simply a template engine, meaning that you write a string and put placeholders in it to be filled by some data. Razor is really easy to use, thus:
hello #name
in Razor would be:
hello <%= name %>
in ASP default inline statements. Thus yeah, many developers recently prefer Razor.
If you want to become a good ASP.NET MVC developer, I suggest to follow these topics as starting point:
Filters
HTML Helpers
Razor Syntax
ViewBag, ViewData, and TempData
Routes
of course, these suggestions need you to know ASP.NET, and MVC, and many more stuff as prerequisites.
Using Razor is indeed a more effective approach then to use ASPX-page markup.
Razor is simpler and cleaner. With "cleanness" comes a better code-walk capabilities. In aspx we had a lot of syntactical junk on the way, and a developer's intention to alter or get to know the code were "wearing off" more quicky.
With Razor, you see a much broader picture of a page's view at a glance.
Razor is not the core of being a good ASP.NET developer though.
The following may be a subjective optinon, but as soon as you realize how web server (ports, urls, routing), Controllers, Views and JSON data fromat tick together, as soon as you are able to quickly parse server-generated JSON model on the client with KnockoutJS or other MVVM framework, making your pages go "alive", you are becoming a developer who can create a web site on his own. You should specialize in something, no doubt, but to be a good developer, you need fully understand how Microsoft Stack of web technologies ticks.
Aman As far as Razor over ASPX concerns, I say yes Razor is widely used in industry and as you are beginner in ASP.NET MVC, I suggest to learn MVC 4. You can get more info on MVC 4 from http://www.asp.net/mvc/mvc4 and here is article series covering new feature in MVC 4 http://www.dotnetexpertguide.com/2011/09/aspnet-mvc-4-article-series.html
I have read 3 books on ASP.NET MVC and 2 books on the Entity Framework. I have been developing in MVC 3 since it was released. Absolutely the best resource I have found is Scott Allen's training courses on ASP.NET MVC 3 on http://pluralsight.com/training/Courses/TableOfContents/aspdotnet-mvc3-intro Scott really knows his stuff.
This isnt just your typical canned developer training that is read from a script by a voice actor. Scott really knows web development and he shares some great inside tips on programming MVC 3. His C# stuff on http://pluralsight.com/training/Courses/TableOfContents/csharp-fundamentals is also very good. No, I do not work for pluralsight, I am just a happy pluralsight.com subscriber.
You must know HTML, CSS, jQuery and JavaScript in order to be an effective and productive MVC 3 developer. Go to http://www.w3schools.com/ and do all of the tutorials on those subjects.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Still i am not familiar with asp.net mvc. Now asp.net mvc is very popular. Before learning it I like to know few things like:
If there is no concept of viewstate then, how control state is maintain during postback? If discuss it in details and if possible give me sample code for persisting control state in mvc.
In webform we often use update panel and other controls of ajax control toolkit. So tell me how people embed ajax functionality in mvc? One option is jquery, but is there any other option too? Is there anything like update panel or ajax enabled controls?
You said it is possible to work with asp.net webform and mvc in same project. So tell me, how data can be pass to webform or aspx file?
How very easily we can migrate any asp.net webform project to mvc?
Is there any easy small project based on mvc, which beginner can dowload and go through the code, to understand flow of mvc project? Just like any shopping cart.
What is strongly type & partial view in mvc?
I have no idea about mvc project type. That is why many question is coming to my mind. Please do not feel irritate to answer all this. I apologize for all the above basic question.
This is borderline subjective and might be closed but I will give it a go at my responses to your questions.
The web, by nature, is stateless. ViewState and Postback are .NET concepts that are not natural to the HTTP protocol. If you absolutely must keep persistence, you will need to look at cookies/session.
You can use a framework (jquery and jquery UI, YUI, etc) or roll your own javascript functions. The concept of web controls (though they 'could' be used in MVC) is gone. You will use standard input, select, button HTML controls.
I have not done this, I cannot provide much help here
Depends on the project and how it was written/coded. There is no straightforward 'conversion' that one can do. MVC vs WebForms are two different paradigms.
MVC Music Store and MVC NerdDinner
Strongly typed views are views that are passed a class (model) that has a specific set of properties defined. Using this model, you can pass only the data you need for that view, do type checking when posting back a form, etc. A partial view is simply a view that does not contain all of the layout (master page) stuff. It is to be used to simply display a subsection of a web page (think of a panel)
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I've been waging a bit of a battle with MVC recently, trying to get it deployed and working correctly on my web host server. While the host (ixwebhosting) has been very prompt and efficient at resolving some of the technical difficulties, I'm still encountering odd behaviours around getting the views to render.
Specific issues I've struck so far are the application not being recognised at all (returning 404) and individual views returning 404s.
Is this typical of other peoples' experience when trying to deploy to a hosted environment or am I just a bit green in this department?
Should I consider falling back to web forms until MVC matures a bit more?
(...) views returning 404s (...)
Actually, some of the problems you've been having may be related to some confusions you are having regarding MVC on the web. For example, a View in web MVC is a presentational unit handed back by the controller to the client. The same View can be used for many resources and action methods. These action methods, in turn, can also return 404s. The ASP.NET MVC tutorials on ASP.NET are good starting points for getting to know MVC.
I thought getting ASP.NET MVC to run on IIS6 would be a hassle, but I had zero problems after following the normal installation guidelines. Even special cases where IIS is involved (caching, redirecting, static content etc) has worked fine on IIS6. On IIS7, of course, there are no issues.
I clicked the Publish option and waited until the site got uploaded via FTP. After that everything worked fine.
ASP.Net MVC is an extension to the .net framework, it is a separate install (at least until .net 4.0).
Does your hosting environment have ASP.Net MVC installed?
It could also be that you are having problems with the routing, therefore a URL is giving a 404 (file not found), because it cannot match a route to the url.
Are the URL's different in your hosting environment?
Are there specific issues you are having?
My personal experience: an ISP that can't support 301 redirects under ASP.NET MVC. But that's not MVC's fault; the ISP just hasn't caught up yet. They are still running IIS6, and ASP.NET MVC is better (less problematic) under IIS7.
MVC 1.0 is stable and mature enough for production applications. I also use elements from MVCContrib (i.e. RenderAction) without problems.
I recently hosted on GoDaddy w/out (any) issues at all! I simply published the site and uploaded it via FileZilla.
I even have a DB and that was no issues what so ever.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
Basically, this 'question' is intended to pool information about best practices in the community. The reasons for this are:
The distinct lack of an community based ASP.NET MVC resource for best practices. Yes, I am aware of wiki.asp.net.
I'm painfully aware that the ASP.NET wiki on ASP.NET MVC is woefully small and terribly out of date and needs fleshing out more by Microsoft before the community does anything with it.
I'm very much interested in best practices in general, having had a fair degree of experience with ASP.NET MVC over the last year, but I'm also mindful that I'm no expert, and that I can definitely improve. This post, I believe, can help that, and you.
I gave some serious thought on whether or not I should ask this question, even going to the lengths of creating a question on meta about creating this question. :)
What I am looking for is for best practice information on all aspects of ASP.NET MVC. Controllers, models, extensions, HTML helpers, route builders, TDD.
In the past, I have found resources, such as Kazi Manzur Rashid's best practices (part 1 and 2) post quite useful, along with Maarten Balliauw's weigh-in, but these have dried up somewhat, and I was hoping for a more dynamic and growing repository of information from different people, rather than just the occasional blog entry from learned individuals. Information like this is few and far between, and ASP.NET MVC community resources even less so.
MVC in general
Model
Feel free to add model links
Views
Controller
Feel free to add controller links
Guidelines:
One "best practice" per answer
Take the time to explain why it should be preferred over the alternatives.
Read existing answers first - if you see one you agree with, up-vote it; if you disagree, down-vote and leave a comment explaining why.
Feel free to edit any answer if you can expand on why it is "best"!
P.S. Please don't just put "Anything by Phil Haack, Scott Guthrie, Rob Conery or Scott Hanselman"!
Use T4MVC to eliminate all magic strings and magic anonymous types in your entire project. This will help you in refactoring later in your project, and (apart from having to still ensure your routes are well-defined) all Action calls get their proper parameters. It changes calls like this:
<%= Html.ActionLink("Link text", "Products", "Details", new { id = Model.Id }) %>
Into:
<%= Html.ActionLink("Link text", MVC.Products.Details(Model.Id)) %>
Keep any and all logic out of your view. Your controller should determine what gets shown - your view should be dumb.
IoC/DI for Controller factory (so I can inject IRepository, ISomeService in controllers constructor)
never access HttpContext directly, build wrapper, so it can be unit tested
Validation framework for model binding validations (xVal or FluentValidation). Built-in validation inside MVC 1 is basic
never use "magic strings": for calling controllers/actions from View, for RouteLink, RenderPartial, RenderAction, ...
never use ViewData, build DTO ViewModel classes. Use AutoMapper for mapping data from domain entities to ViewModel DTO objects for View
ViewModel DTO objects:
BaseViewModel abstract class, with properties for rendering page meta data, menus and all other stuff that appears on every page. All other ViewModel classes inherits from BaseViewModel.
While not a best practices site, the below site is doing great things with asp.net MVC that could probably be considered best practice.
http://www.codeplex.com/MVCContrib
There are 2 free chapters available for the book "MVC in Action".
http://www.manning.com/palermo/
Chapter 12 is best practices.
Keep your controllers as "thin" as possible. Simply have them validate data coming in from the form, and then calling the model (which does all the real work) to get the data to be returned in your next View.
Having complex controllers kind of breaks the MVC concept.
This is how i handle all DropDowns in my application and i wanna share with you cause i think it's sorta best practice:
One EditorTemplate for all DropDownLists in ASP.Net MVC