Posts

Showing posts with the label MVC

ASP.NET MVC–Model Error Visualizer

Image
To scratch my own itch (so to speak), I created a Visual Studio visualizer for ASP.NET MVC, allowing ModelState errors to be seen at a glance. This is particularly useful when debugging async requests when and modelstate are not displayed on screen. The visualizer works on the ModelStateDictionary type, iterating through the dictionary and presenting any errors and the associated property name in a datagridview (see the below screenshots). I built this with VS2012 RC, but the code is simple enough that it should be trivial to modify it to work with older version of VS. The code and download are up on github. Just drop it into your Visual Studio 2012 Visualizers folder and you should be good to go. Feel free to use and abuse (and fork) it in whatever way your heart desires.   Links https://github.com/irwinj/ModelErrorVisualizer https://github.com/irwinj/ModelErrorVisualizer/downloads Visualizer in debug mode     Example For example, when I turn client-side valid...

data-placeholder in MVC3

I ran into an interesting problem this evening with a very quick fix. I’m using the very neat chosen Javascript plugin ( link ) to add some aesthetic and functional sugar to a website’s existing dropdowns. Anyhow, adding default text support (e.g. “Please choose an option”) to a multiple select dropdown is achievable using data-placeholder like this: < select data-placeholder=" Choose a country... " style=" width:350px; " multiple class =" chzn-select ""> Problem is, I am using ASP.NET MVC’s helper syntax to create my dropdownlists and “data-placeholder” is invalid syntax due to the dash character. The following does not work: @Html.DropDownListFor(m => m.SelectedProductIDs, Model.AvaliableProducts.ToSelectList(" ID "," Name "), new { @ class = " chzn-select ", data-placeholder=" Please select a product " }) Happily, Microsoft pulled a rabbit out of the hat and as of MVC3 underscores in html...

Upgrading to ASP.NET MVC 3 Preview 1

Image
Earlier today Scott Gu announced the availability of ASP.NET MVC 3 Preview 1. This release  includes the beginnings of the Razor view engine as well as a bevy of additional features. The following are some notable links with more details: Scott Gu Scott Hanselman Phil Haack Maarten Balliauw Anyhow, I played with the demo and got to wondering how to update an existing ASP.NET MVC 2 project to use the new preview version (obviously I wouldn’t switch production code any time soon…) It was simply a matter of editing my existing ASP.NET MVC 2 (C#) project file and making the following updates: ProjectTypeGuids Replace {F85E285D-A4E0-4152-9332-AB1D724D3325} With {E53F8FEA-EAE0-44A6-8774-FFD645390401} and References Replace <Reference Include="System.Web.Mvc, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" /> with <Reference Include="System.Web.Mvc, Version=3.0....

"$.validator.methods[method] is undefined"

Image
I’ve started developing a new project and have recently been getting into ASP.NET MVC and JQuery a lot more. To make my life easier I decided to use the JQuery Validation libraries to perform my client side validation. I created a simple registration form with three fields – username, password, confirm password. The following is the code I am using:     The code uses a remote call to the IsLoginAvailable action of the user controller which in turn checks if the entered username has already been taken and wraps the response in a JsonResult. This appeared to work fine (validating the field when focus was lost) but upon submitting the form I received the following error:   "$.validator.methods[…] is undefined"   or   "$.validator.methods[method] is undefined"   After debugging with Firebug I found that the validation was failing on a "data" method. Looking at the code I realized I was specifying the username to pass via the data ...

ASP.NET MVC – Object Reference is not set to an instance of an object

Image
In the end I have to chalk this down to incompetence and one of those frustrating error messages that tell you absolutely nothing. I’ve been working on an ASP.NET MVC application and last night decided to use JQTouch to provide an iPhone/Android mobile interface. Doing so should have been extremely straightforward. The planned steps were as follows: Add code in my base ViewEngine to detect if a mobile browser is being used. If so, provide a mobile view rather than a standard one. Create a number of views that use the JQTouch library to format my pages for mobile devices.   I recently came across the Mobile Browser Definition File on Codeplex which can be dumped in the app_browser folder in an asp.net solution in order to provide a bunch of information through Request.Browser. I dumped this into my solution, updated my view engine and implemented a few views with JQTouch. It didn’t take too long and i was feeling pretty good. However, attempting to open my applicati...

ASP.NET MVC Membership Provider Issues

This afternoon I struggled a little with an ASP.NET MVC 2.0 issue. I’m using NHibernate’s export schema capabilities to create my database schema. I have an NUnit project with a bunch of different tests with the sole purpose of re-creating the database and populating some dummy data so that I do not have to do so by hand. I wanted to take this a step further and create some users in my system using Microsoft’s in-built MembershipProvider. Having set up my tests, I received the following message: 'System.TypeLoadException : Could not load type 'OnlineAuctions.Core.Classes.BuyerMembershipProvider' from assembly 'System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. Obviously in this case the system is looking for my provider in the System.Web assembly, not my OnlineAuctions.Core assembly. My config file entry was as follows:   <add name="BuyerMembershipProvider" applicationName="OnlineAuctions" connectionStringName=...

Syncfusion – Essential Studio ASP.NET MVC Edition - $5

On Monday August 10th Syncfusion will offer their Essential Studio ASP.NET MVC edition for $5. The limit is 5 licenses per company and the s/w is licensed per developer with 30 days of subscription coverage. Given that the software is normally $995 this is a steal. Click here for more info. Proceeds go to One Laptop Per Child .