background preloader

MVC

Facebook Twitter

Validation

MVC Storefront Part 22: Restructuring, Rerouting, and PayPal. Templates. Routing. Controls. Windows 2008 Hosting BLOG | Blog about Windows Server 2008, Technologies and Hosting Service. Security Auth. Controllers. ASP.NET MVC 3 Service Location, Part 2: Controllers. Series Index Important Update We've made significant changes to the IoC support in ASP.NET MVC 3 Beta. Please read Part 5 for more information. Controller Creation The most common form of service location today in ASP.NET MVC is for controller creation. In MVC 1.0, we created an interface named IControllerFactory which is responsible for the location and creation of controllers.

This interface was introduced with the explicit desire to support dependency injection of controllers. Update: (31 July 2010) I've added the source code for UnityMvcServiceLocator to the end of this post. Disclaimer This blog post talks about ASP.NET MVC 3 Preview 1, which is a pre-release version. Location: IControllerFactory This is a "singly registered" style service introduced in MVC 1.0.

The logic in ControllerBuilder was updated to attempt to find IControllerFactory first by calling MvcServiceLocator.Current.GetInstance<IControllerFactory>(). CustomNamed.cs Global.asax.cs Location: Controller instances What's Next?

JSON

Errors. Compile Views in Asp.Net MVC 3 with Visual Studio. Why compiled views? First of all I prefer VS.NET to compile the cshtml code at build time because it will notice syntax errors like on any .cs file. Syntax errors are most important when I have to do a quick check-in of all my sources to repository and I need to make sure I will not crash the next test build. On a default project the views are parsed and compiled at runtime when you fist navigate to the url with your browser, in other word the load time of an action will take longer because of the compiler. I prefer to wait a little longer for Visual Studio to check and compile my views then to wait for each one while debugging. How to Fist step is to edit the .csproj file and set the MvcBuildViews value to true. This setting was available since MVC 1 and it works on aspx and cshtml as well. .csproj <MvcBuildViews>true</MvcBuildViews> When you’ll fist build the project if you have a .edmx file inside a MsBuild error will pop-up about EntityDesignerBuildProvider assembly.

Web.config.

ModelBinding

C# Bits: DisplayAttribute “Prompt” or Watermark in Dynamic Data 4 (Visual Studio 2010 & .Net 4.0) In Figure 1 there is another property called “Prompt” and the online help says: Prompt: Gets or sets a value that will be used to set the watermark for prompts in the UI. Figure 1 – Display attribute properties So I set the value and looked at the output UI in Insert mode and there was no water mark so again I just had to “make it so”.

So I decided to use the Ajax Control Toolkit’s TextBoxWatermark to achieve this. Note: This example applies this to the Text and DateTime fields template, but it could also be applied to other templates that are based on Textboxes (e.g. Integer, Decimal etc.) I’ve created a watermarked CSS class and added it to the site.css file. Listing 1 – watermarked CSS class Listing 2 – TextBoxWarterMarkExtender I’ve also added the TextBoxWarterMarkExtender to both the Text_Edit.ascx and DateTime_Edit.ascx files see Listing 2 then we need to make the changes to the code behind files. Listing 3 – Watermarked region of the Text_Edit.ascx.cs Page_Load event.

TimeZones

ModelMetaData. EditorTemplates. Custom Attributes When Using Html.TextBoxFor. 31. January 2010 20:52 / Michael / Software / Comments (5) I finnally got a few minutes to work on the new asp.net mvc 2 this weekend. I was working through the example on Model Validation Scott Guthrie did on Jan 15th and found my self wanting to resize the text boxes on my input form. In his example he is using Html.TextBoxFor and calling into his model object for the attributes of the input tag. This seemed really nice and I worked with it.

This seemed to work but I was trying to add a class attribute so I could affect the text boxes. This will not compile. This got me right where I wanted to be. Since this was a change I would not mind having site wide I thought about chaning it there or adding a input[type="text"] to my pages css. Currently rated 5.0 by 7 people.

MVC Scaffolding Templates

MVC3. HtmlHelper. Unit Testing. Working with SSL at Development Time is easier with IISExpress. How To Use ASP.NET MVC in Website rather than Web Application Project. I recently started getting to know the ASP.NET MVC Framework (more specifically the Preview 4 release). The first thing I noticed upon installation is that it only comes with a Web Application Project Template. There is no regular ASP.NET Website template. So, I decided to try converting the Web Application Project Template to a regular ASP.NET Website. I actually prefer to use Website projects instead of Web Application projects since it gives a little more flexibility to deploy changes to the website after the website is already live.

I only needed to make a couple small changes when copying over the code into a new ASP.NET Website: Convert the .aspx pages from using CodeBehind to CodeFile. That's pretty much it, now I have a nice ASP.NET MVC Website template that I can use. The ASP.NET MVC release I used for this was the ASP.NET MVC Preview 4 release available on CodePlex. NuGet Package of the Week #2 - MvcMailer sends mails with ASP.NET MVC Razor Views and Scaffolding.

News

View Engines. Tutorials. Productivity Enhancements in ASP.NET MVC 3. Practical ASP.NET Productivity Enhancements in ASP.NET MVC 3 Peter Vogel takes a look at Razor and the productivity gains in generating views that ASP.NET MVC 3 provides to developers. As I discussed in earlier columns on ASP.NET MVC , I think that the chief issue organizations will be concerned with in adopting the tool will be developers' productivity compared to ASP.NET. While organizations may value the additional reliability that extending test driven development throughout the whole application will give them, they may balk at giving up the powerful UI controls (both in the box and from the third party market) that come with ASP.NET.

For instance, while I've seen several articles on how to support paging in an ASP.NET table, none of them are as quick as checking off the paging option in ASP.NET DataView. Obviously, if ASP.NET MVC can achieve productivity levels in the same ballpark as ASP.NET when it comes to generating an application's UI -- the View -- these concerns disappear.