Tuesday, October 19, 2010

How to set the selected item in an MVC Dropdownlist

The first parameter to the Html.DropDownList needs to be a name that does not match the name in your model. Below I used "OptionId" instead of "Options".

View

<%= Html.DropDownList("OptionId",Model.Options) %>

Controller

SelectListItem item1 = new SelectListItem();

item1.Text = "Red";

item1.Value = "Red";

item1.Selected = false;

viewModel.Options.Add(item1);

SelectListItem item2 = new SelectListItem();

item2.Text = "Green";

item2.Value = "Green";

item2.Selected = true;

viewModel.Options.Add(item2);

SelectListItem item3 = new SelectListItem();

item3.Text = "Blue";

item3.Value = "Blue";

item3.Selected = false;

viewModel.Options.Add(item3);

Tuesday, October 5, 2010

How to create a modal dialog in jQuery and prevent scrolling in background


$(document).ready(function() {

$("#dialog").dialog({ autoOpen: false

, modal: true

, buttons:

{

"Cancel": function() {

$(this).dialog("close");

$("body").css("overflow", "auto"); }

, "Save": function() {

$(this).dialog("close");

$("body").css("overflow", "auto"); }

}

});

});


function RenameFile(filename, id) {

$("#OldFilename").html("From: " + filename);

$("#NewFilename").val(filename);

$("#dialog").dialog("open");

$("body").css("overflow", "hidden");

}


<div id="dialog" title="Change Filename">

<p id="OldFilename"><b>From: </b>oldfilename.doc</p>

<p><b>To: </b>

<input id="NewFilename" type="text" style="width:200px" /></p>

</div>


<a style="cursor:hand;text-decoration:underline;color:Blue" onclick="javascript:RenameFile('<%= Html.Encode(doc.FileName) %>',<%= doc.PathID %>)">rename</a>



Wednesday, September 29, 2010

How to resolve unresolved type System.Web.Security.MembershipCreateStatus which appears after converting from vs2008 to vs2010

I upgraded a project I was working on from vs2008 to vs2010 and started getting an error for an unresolved type: System.Web.Security.MembershipCreateStatus.

My project was targeting the .NET Framework 3.5 and during the conversion, I selected not to change the target to the .NET Framework 4.0.

This issue was occurring in my Test project which was generated automatically when I created an MVC 2 project in vs2008. In vs2010, test projects cannot target the 3.5 Framework (by design). The quick fix was to delete AccountController.cs in the test project.

A better solution would be create another MVC2 project in vs2010 and use the generated Test project.

Thursday, September 23, 2010

How to add a configuration file to your class library

I have a web project with some configuration settings in the web.config. I added a class library to the project and realized I could not access those values from the class library. The solution is to add an app.config file to the class library project and copy the configuration settings from the web.config to the app.config.

To access ConfigurationManager from the class library, I need to add a reference to the System.Configuration .Net assembly.

If you don't like having the settings in both places, you could retrieve the configuration values for the web application by using the class library (app.config), and remove the configuration values from the web.config.


Wednesday, September 22, 2010

How to insert a tab in Microsoft Word when your cursor is in a table cell

When you're working in a table in Word, the tab key will bring you to the next cell (not insert a tab).

When you want to insert a tab, use [Ctrl][Tab] instead

Tuesday, September 21, 2010

How to create FREE flowcharts online

This is a pretty cool product. http://www.gliffy.com It's easy to use like Visio, which no longer comes with my MSDN subscription :( . You can create .pdf, png or jpgs.


Monday, September 20, 2010

How to display hidden files and folders in Windows 7

1. Start | Control Panel | View By: Category
2. Click Appearance and Personalization
3. Below "Folder Options" there is a link for "Show hidden files and folders"
4. Then select the radio button "Show hidden files, folders and drives"
5. Click [ok]