MVC 5 Placeholders, Prompts and Watermarks

I have noticed an issue with the MVC project in Visual Studio that I am sure others have seen too.  I say this because I have seen a number of solutions in StackOverflow and the ASP.Net forums.  This post is not about some great way to write your own extensions and automagically have the placeholder set in the HTML that is displayed to the user.  No, this is a much simpler method.

Just manually set the placeholder in your Razor syntax.  Chances are you are going in there anyway to tweak a few things instead of using what Visual Studio scaffolded for you.  I would still recommend setting the Prompt in your model though, I suspect that one day this will get fixed or you might actually need it to be automatically generated.  In fact I’d say that if you are writing your own Edit Templates you should include the small extra step to make it auto-generated.

If you are not doing that, here is the easiest fix or work around.

Given this simple model for a customer phone number.  You can ignore that Regex if it doesn’t work for you, in my example this assumes a US phone number with an optional +1 in front of the number, or feel free to take that and make it your own. Normally you would want to use the Prompt argument as part of your display settings, so still do that in your models.

[RegularExpression("^(\\+?1?( ?.?-?\\(?\\d{3}\\)?) ?.?-?)?(\\d{3})( ?.?-? ?\\d{4})$", ErrorMessage = "Please enter a properly formatted Phone.")]
[Display(Name = "Customer Phone", Prompt = "(123) 456-7890")]
public string Phone { get; set; }

Here is what we would put in our Razor syntax to generate a form field with the watermark. As part of your htmlattributes object add an attribute for placeholder and set that to what you entered for your prompt.

<div class="form-group">
    @Html.LabelFor(model => model.Phone, htmlAttributes: new { @class = "control-label col-md-2" })
    <div class="col-md-10">
        @Html.EditorFor(model => model.Phone, new { htmlAttributes = new { @class = "form-control", placeholder = "(123) 456-7890" } })
        @Html.ValidationMessageFor(model => model.Phone, "", new { @class = "text-danger" })

Enabling Power User Mode In Opera

Opera has a neat feature for its settings called Power User mode.  What is even neater is how you enable this mode.

  1. Bring up the settings tab
  2. Type in that old game code with your arrow keys Up Up Down Down Left Right Left Right
  3. Then type B A to finish the code

Just to be clear the whole code is the arrow keys for direction followed by B and then A, you don’t need to hold shift down or anything.

Up Up Down Down Left Right Left Right B A

One of the really cool things you can do in power user mode is remove the search box from the Speed Dial page.  Personally I prefer Bing but right now you cannot change this box from Google.  So removing it gives me more immediate space in my Speed Dial.

Dragging Files To OneNote

I just learned something really cool about OneNote.  I was not sure how it would respond if I did a drag and drop of a PDF file to a OneNote page.  The result is impressive.  Well done OneNote team!

Insert Link, Insert a copy of the file onto the page, Insert the file as a printout so I can add notes to it

Drag and Drop Dialogue

Collection Was Modified; Enumeraton Operation May Not Execute

Some Background

This was a very interesting bug for me to track down.  Initially it did not bubble up as the error that is in this title.  Initially it revealed itself as an out of bounds error when I tried to set IsOpen to true for a ContextMenu in a Silverlight project.  After lots of debugging I finally landed on this culprit.

The Task

The task I was trying to accomplish was pretty straight forward.  Given a List<T> remove any duplicate entries based on a given object.  Again, a straight forward task, or so I thought.

foreach(MyClass item in myListOfMyClass)
    if(item.SomeValue == objectOfMyClass.SomeValue)

Read the rest of this entry

Left or Right Curly Braces

Should you put your curly braces on the left or right?

function foo(){
    //My curly brace is on the right.

function bar()
    //My curly brace is on the left.

Read the rest of this entry

One Advantage of CodeWriter

A few weeks ago I posted about WebMatrix, which is a really nice light weight tool if you don’t want to fire up full Visual Studio.  I also indicated that I was using CodeWriter.  I have noticed one real advantage that CodeWriter has over WebMatrix.  I can run CodeWriter on my Surface 2.  My Surface 2 is not a pro version so I cannot run Visual Studio on it, and in turn I cannot run WebMatrix on it.

I will admit, I do not do a whole lot of dev work on my Surface 2.  In fact I normally write something up in CodeWriter so I can copy/paste it into OneNote or test something really small.

The JavaScript Object Literal

I have been really trying to beef up my JavaScript skills lately.  One really interesting aspect from this experience is how cool I find the object literal.

You can use it to create really any kind of data structure you desire.  It can hold the primitive types like strings and numbers, it can hold objects like arrays or other object literals, and it can store functions.  I created a fiddle at JSFiddle to demonstrate the object literal.

Here is the JavaScript for my object literal which I call oPerson.

var oPerson = {
    firstName: "John",
    lastName: "Doe",
    age: Math.floor((Math.random() * 33) + 17),
    "favorite color": "Blue",
    Interests: {
        movies: ["The Blob", "History of the World Part 1", "Ferris Bueller's Day Off"],
        bands: ["Lacuna Coil", "Soft Cell", "Naked Eyes"]
    greeting: function () {
        return "Hello, my name is " + this.firstName + " " + this.lastName + ".";

Read the rest of this entry

Some History Of I, J, And K

I learned a little bit of geek history today.  A lot of us have used the variable I (or i rather) in our loops, and sometimes for nested loops we would use j and then k.  Do you know where that started?

Apparently it started in FORTRAN.  The variables i, j, and k were to be only used for integer type variables.  I am sure there is more to it than that but a quick search gave two different sources that confirm it.



I know this is nothing ground breaking or anything, I just thought it was something neat.

WebMatrix Collapsible Areas

Just a quick post about something I noticed in WebMatrix today.  It has some very cool collapsible areas, something I wish I had in Visual Studio 2013 Premium.  Take a look at the screenshot below, you’ll see what I am talking about.  Don’t worry about the code, it is just some basic JavaScript I threw together for this post.

WebMatrix Collapsible Areas

Scheduling Prometric Exam Advice

I have a bit of advice to pass on that I just learned at the School of Hard Knocks.

What Happened

I wanted to schedule my next exam with Prometric.  I had entered everything, including my 3 for 1 voucher, but I needed to double check the date.  So I use the go back button on their page (not the browser) to look at the dates.  I kept the same date and continued to the page I was on using the buttons on their page.

My voucher was no longer applied.  I tried to add it again but was given the message that it was no longer valid.  So I scheduled the exam anyways because I didn’t want the date to fill up and hoped that it was applied to my account.

I used their button to schedule another exam and it let me put the voucher on it, but the price did not change!  So I will need to contact Prometric to get it fixed.

What Should Have Happened

My voucher should have remained and not disappeared when I used their site navigation to go back.


Do NOT apply your voucher until you are ready to check out.  Even if you think you are ready, wait a few minutes before you apply it before finishing your process just to make sure.

After Contacting Prometric

To fix it I need to cancel my current exam at a fee of $35 and start over again.  Of course I have the option of just keeping the current exam and applying my voucher on my next one, which is even worse as it is a 3 for 1 voucher.  These exams are $150 each.  So I’ll take the $35 hit to save $300.  Of course as luck would have it I am not able to cancel it now, I get a message on their site that an error occurred.


Get every new post delivered to your Inbox.

Join 224 other followers