Ajaxify your MVC form in 30 seconds

I was playing around with the ASP.NET MVC 2 Framework and needed to submit my form using Ajax instead of a full form post. I noticed the MicrosoftAjax.js and MicrosoftMvcAjax.js file that came with the project so I had high hopes for something good being included in the framework that would simplify that task. And indeed. By simply using the AjaxHelper instead of the HtmlHelper you can have your form submitted via Ajax. MVC does all the hard work for you.

Simply  replace

<% using (Html.BeginForm()) { %>


<% using (Ajax.BeginForm(new AjaxOptions() { OnComplete = "OnFormSubmitComlete" })) {%>

and you’re done. No changes to your Controller are required. There are some nice AjaxOptions you can specify and BeginForm has a bunch of overloads as well. In this case I’ve specified a javascript method name “OnFormSubmitComlete” to be called after the form has been submitted and the response received.

<script type="text/javascript">
function OnFormSubmitComlete(content)
alert("Saved with Ajax. Awesome!");

Make sure you’re including the MicrosoftAjax.js and MicrosoftMvcAjax.js scripts that come with your project.

Posted in .NET | Tagged , , , | Leave a comment

Cloning SharePoint 2010 development images (for Hyper-V)

Before we begin, I´d like to point out the obvious: You want to clone a VM that is as clean as possible (without needing to install all the software on each clone of course). So clone your VM before creating any sites, since all references will be broken when you change the name.

This has been tested with a VM containing the following software:

  • Windows Server 2008 R2
  • SQL Server 2008 Express
  • SharePoint 2010 Enterprise
  • Visual Studio 2010 Premium
  • Office Professional Plus 2010

First, the best way to clone the VM for use in your Hyper-V setting. Contrary to what you might expect, this is not by using the export/import functions of Hyper-V Manager. This is actually meant for backup/restore.

The best way I have found is to just stop the VM you want to clone, copy the VHD, create a new VM definition and attach it to the copied VHD.

Next, the VM must be renamed. These steps are based on the MOSS 2007 cloning steps outlined here: http://www.sharepointdevwiki.com/display/public/Cloning+a+SharePoint+Virtual+Machine

  1. Stop the SharePoint Search services(s). I stopped both the “SharePoint Foundation Search V4” and “SharePoint Server Search 14” services to be sure.
  2. Go to System Properties and rename the VM, but don’t restart yet.
  3. Open “SQL Server Management Studio” and connect to “(local)”.
  4. Run the following query:
    EXEC sp_dropserver '<old_name>'
    EXEC sp_addserver '<new_name>', 'local'
  5. Run the “renameserver” stsadm command:
    stsadm -o renameserver -oldservername <old server name> -newservername <new server name>
  6. Now restart the VM.
  7. Rebuild Central Administration:
    psconfig -cmd adminvs -provision -port 12345 -windowsauthprovider onlyusentlm
  8. Restart IIS.
  9. Open Central Administration and delete the applications that are based on the old machine name.

Aaaand, you’re good to go.

Posted in .NET | Tagged | 3 Comments