ASP.NET MVC – Using Controller.UpdateModel when using a ViewModel

2

Posted by Joe | Posted in MVC | Posted on 17-02-2010

When updating a model in MVC it is common to use the Controller.UpdateModel method.  I recently ran into an issue where I was using a custom ViewModel which meant that UpdateModel could not map the updated data back to my model object. The solution to this was a simple one, but not as obvious as it should be due to intellisense not picking up the method’s overloads when the generic type is inferred. 

Read the rest of this entry »

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit

Creating a Delete link with MVC using POST to avoid security issues

0

Posted by Joe | Posted in Ajax, MVC, jQuery | Posted on 16-02-2010

It is fairly common to have a list of records with a hyperlink to delete a record.  The problem here is that with MVC the hyperlink will use a GET request to delete a record.  This is a fairly big security issue as anybody can browse to the URL and delete a record from your system.  In this post I’ll explain how you can use the Ajax helpers to create a hyperlink that will call your delete method without using GET.

Read the rest of this entry »

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit

Edit in place / inline editing with jQuery, jTemplates and ASP.NET

0

Posted by Joe | Posted in ASP.NET, Ajax, JavaScript, jQuery | Posted on 12-01-2010

Download source

In this post I talked about how to use the jTemplates plugin for jQuery. Using my final example in the post I thought it would be cool to try and add some ‘edit in place’ functionality to the table.

For this to work I’ve created a Data Access Layer using Linq to XML. My web service then uses this DAL to save and retrieve my data.

Read the rest of this entry »

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit

Linq to XML Tutorial

0

Posted by Joe | Posted in ASP.NET, C#, Linq, XML | Posted on 08-01-2010

Download source

This is an introduction to Linq to XML showing how to read, insert, update and delete from an XML file.

Read the rest of this entry »

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit

Using the jTemplate jquery plugin with ajax and ASP.NET

6

Posted by Joe | Posted in ASP.NET, Ajax, JavaScript, jQuery | Posted on 05-01-2010

Download source

A guy in work introduced me to jTemplates, a template engine plugin for jQuery. It allows you to easily bind JavaScript objects to a defined template and also has some other nifty features.

I’ve found jTemplates to be particularly good when using ajax to display any information quickly and easily.

First I’ll explain how to create a simple template to display data, and then how to use the foreach and cycle features.

Read the rest of this entry »

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit

Using jQuery to make ajax calls to an ASMX web service using ASP.NET

0

Posted by Joe | Posted in ASP.NET, Ajax, C#, JavaScript, jQuery | Posted on 04-01-2010

Download source

Making ajax calls to an ASP.NET web service using jQuery is too easy.  In this post I’ll explain how to do it!

Read the rest of this entry »

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit

JSON Serialization using the DataContractJsonSerializer and C#

0

Posted by Joe | Posted in ASP.NET, C#, JavaScript | Posted on 29-12-2009

Download source code

Previously I’d done JSON serialization using the JavaScriptSerializer which is part of AJAX Extensions 1.0, but this is now obsolete.

.NET 3.5 introduced the DataContractJsonSerializer class.  The class sits in the System.Runtime.Serialization.Json namespace which is curiously hidden away in the System.ServiceModel.Web assembly.

The DataContractJsonSerializer can serialize a class that contains the Serializable attribute or any class defined as a DataContract.

Read the rest of this entry »

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit

Linq to SQL Tutorial – Linq to SQL Generic Framework using reflection

0

Posted by Joe | Posted in ASP.NET, C#, Linq | Posted on 28-12-2009

Download source code

In a previous post; Base Repository/Business Logic wrapper, I talked about a basic Linq to SQL Framework I created. I then extended it in my ObjectDataSource binding with paging and sorting post to show how to use it with the ObjectDataSource.

The problem was that although it worked quite nicely for getting all records and getting by ID, if I wanted to perform any specific filtering I had to create a derived repository class with a specific method for each query.

In this post I’ll explain how I have extended this framework using reflection to allow filtering on multiple columns without having to created separate repository objects.

Read the rest of this entry »

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit

Linq to SQL Tutorial – Using Load Options to preload data immediately without lazy loading

0

Posted by Joe | Posted in ASP.NET, C#, Linq | Posted on 23-11-2009

Download source

With Linq to SQL lazy loading is used by default. That means that if one object contains another object, the child object will only be loaded when first accessing it. Using Load Options it is possible to tell Linq to SQL to also load the child object at the same time as loading it’s parent.

Read the rest of this entry »

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit

ASP.NET FormView SetFocus

0

Posted by Joe | Posted in ASP.NET, C# | Posted on 20-11-2009

I have FormView and on changing to Edit mode I wanted to set focus to the first textbox. I thought I’d do this hooking into the ModeChanged event but this doesn’t work as the textbox hasn’t been rendered.

I then tried overriding the Render method and setting the focus after rendering; at this point the control was created but I get an exception to say focus can only be set in PreRender, but in PreRender the control won’t be available.

One way I found to get this to work was to set the focus in a handler for the DataBound event of the FormView.

Read the rest of this entry »

Post to Twitter Post to Delicious Post to Digg Post to Facebook Post to Reddit