Pro ASP.NET MVC 4

Pro ASP.NET MVC 4

Adam Freeman

Language: English

Pages: 756

ISBN: 1430242361

Format: PDF / Kindle (mobi) / ePub


The ASP.NET MVC 4 Framework is the latest evolution of Microsoft’s ASP.NET web platform. It provides a high-productivity programming model that promotes cleaner code architecture, test-driven development, and powerful extensibility, combined with all the benefits of ASP.NET.

ASP.NET MVC 4 contains a number of significant advances over previous versions. New mobile and desktop templates (employing adaptive rendering) are included together with support for jQuery Mobile for the first time. New display modes allow your application to select views based on the browser that's making the request while Code Generation Recipes for Visual Studio help you auto-generate project-specific code for a wide variety of situtations including NuGet support.

In this fourth edition, the core model-view-controller (MVC) architectural concepts are not simply explained or discussed in isolation, but are demonstrated in action. You’ll work through an extended tutorial to create a working e-commerce web application that combines ASP.NET MVC with the latest C# language features and unit-testing best practices. By gaining this invaluable, practical experience, you’ll discover MVC’s strengths and weaknesses for yourself—and put your best-learned theory into practice.

The book's authors, Steve Sanderson and Adam Freeman, have both watched the growth of ASP.NET MVC since its first release. Steve is a well-known blogger on the MVC Framework and a member of the Microsoft Web Platform and Tools team. Adam started designing and building web applications 15 years ago and has been responsible for some of the world's largest and most ambitious projects. You can be sure you are in safe hands.

 

 

 

 

 

 

 

 

 

 

 

 

 

static void RegisterRoutes(RouteCollection routes) { routes.MapRoute("MyRoute", "{controller}/{action}/{id}", new { controller = "Home", action = "Index", id = "DefaultId" }); } } } The route’s URL pattern defines the standard controller and action variables, as well as a custom variable called id. This route will match any zero-to-three-segment URL. The contents of the third segment will be assigned to the id variable, and if there is no third segment, the default value will be used.

criteria that the factory is seeking. If you want to create custom controller factory behavior, you can conFigure 17-the settings of the default factory or override some of the methods. This way, you are able to build on the useful convention-over-configuration behavior without having to re-create it—a task which, we noted earlier, is pretty complicated and painful. In the sections that follow, we show you different ways to tailor controller creation. Prioritizing Namespaces In Chapter

type="submit" value="Submit" />

Note Using the helper methods to generate HTML elements like form and input is not compulsory. If you prefer, you can code them using static HTML tags and populate values using view data or view model objects, just as we did in this section. The HTML that we generate from the helper methods in the following sections is very clean and there are no special attribute values or sneaky tricks that mean you have to use them—but they make it

ModelState.IsValidField method to ensure that we have valid ClientName and Date values to work with. This means we will not generate a model-level error unless the previous checks on the properties have been successful. We register a model-level error by passing the empty string ("") as the first parameter to the ModelState.AddModelError method, like this: ... ModelState.AddModelError("", "Joe cannot book appointments on Mondays"); ... We can then update the MakeBooking.cshtml view file to

layout). We how have all the elements we need to test editing products. Run the application, navigate to the Admin/Index URL, and make some edits. Click the Save button. You will be returned to the list view, and the TempData message will be displayed, as shown in Figure 10-12. Figure 10-12. Editing a product and seeing the TempData message The message will disappear if you reload the product list screen, because TempData is deleted when it is read. That is very convenient, since we do

Download sample

Download