<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Fremus.co.za &#187; ASP.NET MVC</title>
	<atom:link href="http://www.fremus.co.za/blog/category/aspnet-mvc/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.fremus.co.za/blog</link>
	<description>Demistifying Life and Web Development</description>
	<lastBuildDate>Sun, 27 Nov 2011 15:56:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Daily Code – Day 1 – ASP.NET MVC: Using Json() to create dynamic types</title>
		<link>http://www.fremus.co.za/blog/2011/04/daily-code-%e2%80%93-day-1-%e2%80%93-asp-net-mvc-using-json-to-create-dynamic-types/</link>
		<comments>http://www.fremus.co.za/blog/2011/04/daily-code-%e2%80%93-day-1-%e2%80%93-asp-net-mvc-using-json-to-create-dynamic-types/#comments</comments>
		<pubDate>Wed, 20 Apr 2011 16:26:02 +0000</pubDate>
		<dc:creator>fr3dr1k</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.fremus.co.za/blog/?p=784</guid>
		<description><![CDATA[Do you ever have to return more than one result set, or dataset for that matter to some UI? If for instance you have a piece of UI that allows users to create something new with by entering a value into a textbox AND by selecting a value from a dropdown list AND you are [...]]]></description>
			<content:encoded><![CDATA[<p>Do you ever have to return more than one result set, or dataset for that matter to some UI? If for instance you have a piece of UI that allows users to create something new with by entering a value into a textbox AND by selecting a value from a dropdown list AND you are displaying existing (already added) data in a table below the dropdown and the textbox and they all appear on a modal dialog. Logic tells me that when I click to activate the dialogue the dropdownlist and the table with the data must be populated with data. It also tells me that its not feasible to make two jQuery ajax calls, one for the data in the table and another for the data in the dropdown. What to do? Return arrays of objects with one ajax call and bind it to the UI. How do you return arrays of objects in ASP.NET MVC? Well you can create dynamic objects like this:</p>
<pre name="code" class="csharp">

        [HttpPost]
        public JsonResult GetOfferings()
        {
            offerings = new OfferingRepository();
            offerings.GetOfferings();
            offeringTypes = new OfferingTypeRepository();
            offeringTypes.GetOfferingTypes();
            return Json(
                new
                {
                    Offerings = offerings.Offerings.Select(t =>
                        new
                        {
                            OfferingName = t.OfferingName,
                            OfferingId = t.Id
                        }),
                    OfferingTypes = offeringTypes.OfferingTypes.Select(t =>
                        new {
                            OfferingTypeName = t.OfferingTypeName,
                            OfferingTypeId = t.Id
                        })
                });
        }
</pre>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save" onclick="urchinTracker('/outgoing/www.addtoany.com/share_save?referer=');"><img src="http://www.fremus.co.za/blog/wp-content/plugins/add-to-any/favicon.png" width="16" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.fremus.co.za/blog/2011/04/daily-code-%e2%80%93-day-1-%e2%80%93-asp-net-mvc-using-json-to-create-dynamic-types/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Daily Code &#8211; Day 1 &#8211; ASP.NET MVC Execution Pipeline</title>
		<link>http://www.fremus.co.za/blog/2011/04/daily-code-day-1-asp-net-mvc-execution-pipeline/</link>
		<comments>http://www.fremus.co.za/blog/2011/04/daily-code-day-1-asp-net-mvc-execution-pipeline/#comments</comments>
		<pubDate>Wed, 20 Apr 2011 07:39:05 +0000</pubDate>
		<dc:creator>fr3dr1k</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>

		<guid isPermaLink="false">http://www.fremus.co.za/blog/?p=780</guid>
		<description><![CDATA[I have decided to stop whining about not being able to do certain pieces of code by learning the pieces of code needed to do particular things. With that in mind I am going to try and write a blog post everyday for the next year about code and concepts. Usually a piece of code [...]]]></description>
			<content:encoded><![CDATA[<p>I have decided to stop whining about not being able to do certain pieces of code by learning the pieces of code needed to do particular things. With that in mind I am going to try and write a blog post everyday for the next year about code and concepts. Usually a piece of code has a concept behind it and usually it is required that you understand the concept before you rush in and code. Its understood that we don&#8217;t always follow the approach of understanding code before we implement it, but it should nonetheless be reason to try and understand it.</p>
<p>This morning I started reading up on the ASP.NET MVC 2 processing pipeline, which differs quite a bit from ASP.NET Webforms. Its important to understand the processing pipeline because it allows you to implement custom functionality such as your own Controller factory. Understanding the processing pipeline is also important because you understand what is possible and what not.</p>
<p>Webforms use a page life cycle whereas ASP.NET MVC starts off by processing an incoming request which it first tries to match up  with a file on disk. If it finds that the incoming request maps to a physical file it serves the physical file. If however it finds that the incoming request is for a .NET type that implements IRoutehandler, it looks in your Global.asax file at the routes in your RouteTable and looks to see if the request matches any of the route entries. MvcRouteHandler then knows how to take the request and invoke the relevant controller class. The controller is a class that inherits from a class called Controller which exposes the methods within that class to action methods, i.e. they can implement ActionResults or ViewResults which is rendered by a viewengine.</p>
<p>I think that describes the execution pipeline quite well.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save" onclick="urchinTracker('/outgoing/www.addtoany.com/share_save?referer=');"><img src="http://www.fremus.co.za/blog/wp-content/plugins/add-to-any/favicon.png" width="16" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.fremus.co.za/blog/2011/04/daily-code-day-1-asp-net-mvc-execution-pipeline/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Paging for ASP.NET MVC</title>
		<link>http://www.fremus.co.za/blog/2011/02/paging-for-asp-net-mvc/</link>
		<comments>http://www.fremus.co.za/blog/2011/02/paging-for-asp-net-mvc/#comments</comments>
		<pubDate>Sat, 12 Feb 2011 15:51:22 +0000</pubDate>
		<dc:creator>fr3dr1k</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[jquery]]></category>

		<guid isPermaLink="false">http://www.fremus.co.za/blog/2011/02/paging-for-asp-net-mvc/</guid>
		<description><![CDATA[I bought Steve Sanderson’s book Pro ASP.NET MVC about 6 months ago and I must admit its a real winner for the single reason that the code and explanations are clear and to the point, and he actually gives you code you can use easily. In chapter 4 he builds a paging helper class which [...]]]></description>
			<content:encoded><![CDATA[<p>I bought Steve Sanderson’s book <a href="http://blog.stevensanderson.com/category/pro-aspnet-mvc/" target="_blank" onclick="urchinTracker('/outgoing/blog.stevensanderson.com/category/pro-aspnet-mvc/?referer=');">Pro ASP.NET MVC</a> about 6 months ago and I must admit its a real winner for the single reason that the code and explanations are clear and to the point, and he actually gives you code you can use easily. In chapter 4 he builds a paging helper class which is really cool and works well when you bind the model to your view but the way he implements it could be made better by creating a class that accepts a generic type and I also want to use this method for Ajax/jQuery. The code in his book for the PagingInfo class looks like this:</p>
<pre class="csharp" name="code">public class PagingInfo
{
	public int TotalItems { get; set; }
	public int ItemsPerPage { get; set; }
	public int CurrentPage { get; set; }
	public int TotalPages
	{
		get
		{
			return (int)Math.Ceiling(decimal)TotalItems / ItemsPerPage;
		};
	}
}</pre>
<p>In the controller in his book he then creates a class called, ProductsListViewModel, which has two properties, IList
<products> Products and PagingInfo PagingInfo:</p>
<pre class="csharp" name="code">public class ProductsListViewModel
{
	public IList
<products> Products { get; set; }
	public PagingInfo PagingInfo { get; set; }
}</pre>
<p>On a side note I must say I agree in part with Jeffrey Richter in his book C# via CLR that properties are a weird mix of a method and not a method and sometimes it does feel as if what you are doing in a property might work in a method also. But I digress. In his controller he has a action result that binds the ProductsListViewModel to the view: </p>
<pre class="csharp" name="code">
public ViewResult List([DefaultValue(1)] int page)
{
	var productsToShow = productsRepository.Products;
	var viewModel = new ProductsListViewModel
	{
		Products = productsToShow.Skip((page - 1) * PageSize).Take(PageSize).ToList();
		PagingInfo = new PagingInfo {
			CurrentPage = page,
			ItemsPerPage = PageSize,
			TotalItems = productsToShow.Count()
		}
	}
	return View(viewModel);
}
</pre>
<p>Before I continue there are a few things to note about the controller method and the first is that I have not shown the productsRepository and its implementation and the second thing to note is that PageSize is a public variable declared in the controller class. </p>
<p>The code works great, and I have used it now in several places and I really like it because it feels as if the PagingInfo class provides an abstraction that the entity you are paging does not know about. This makes it feel light and easy to implement. I do however think it might be useful to create a class that accepts a generic type instead. So what I have done is create a class called EntityViewModel, and it looks a bit like this:</p>
<pre name="code" class="csharp">
public class EntityViewModel<T>
{
	private List<T> listOfEntities;
	private PagingInfo pagingInfo;

	public List<T> ListOfEntities
	{
		get { return listOfEntities; }
		set { this.listOfEntities = value; }
	}
	public PagingInfo PagingInfo
	{
		get { return pagingInfo; }
		set { this.pagingInfo = value; }
	}
}
</pre>
<p>This will mean that when I create a controller method I can do this instead:</p>
<pre name="code" class="csharp">
public ViewResult List([DefaultValue(1)] int page)
{
	var productsToShow = productsRepository.Products;
	var viewModel = new EntityViewModel<Product>
	{
		ListOfEntities = productsToShow.Skip((page - 1) * PageSize).Take(PageSize).ToList();
		PagingInfo = new PagingInfo {
			CurrentPage = page,
			ItemsPerPage = PageSize,
			TotalItems = productsToShow.Count()
		}
	}
	return View(viewModel);
}
</pre>
<p>
Which to me seems a bit more flexible. It doesnt end there though because I want to consume the controller method using jQuery and jQuery templates and for that I need to change the controller method slightly:
</p>
<pre name="code" class="csharp">
public JsonResult List([DefaultValue(1)] int page)
{
	var productsToShow = productsRepository.Products;
	var viewModel = new EntityViewModel<Product>
	{
		ListOfEntities = productsToShow.Skip((page - 1) * PageSize).Take(PageSize).ToList();
		PagingInfo = new PagingInfo {
			CurrentPage = page,
			ItemsPerPage = PageSize,
			TotalItems = productsToShow.Count()
		}
	}
	return Json(viewModel);
}
</pre>
<p>Now I can get a JSON result, AND it has paging which is totally awesome!</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save" onclick="urchinTracker('/outgoing/www.addtoany.com/share_save?referer=');"><img src="http://www.fremus.co.za/blog/wp-content/plugins/add-to-any/favicon.png" width="16" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.fremus.co.za/blog/2011/02/paging-for-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a CMS with ASP.NET MVC 3 Razor &#8211; Conceptualisation</title>
		<link>http://www.fremus.co.za/blog/2011/01/building-a-cms-with-asp-net-mvc-3-razor-conceptualisation/</link>
		<comments>http://www.fremus.co.za/blog/2011/01/building-a-cms-with-asp-net-mvc-3-razor-conceptualisation/#comments</comments>
		<pubDate>Fri, 28 Jan 2011 13:41:10 +0000</pubDate>
		<dc:creator>fr3dr1k</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[ASP.NET MVC 3]]></category>

		<guid isPermaLink="false">http://www.fremus.co.za/blog/?p=741</guid>
		<description><![CDATA[I have been working with ASP.NET MVC 2.0 for the last couple of months, 6 or so and the thing that I love the most about ASP.NET MVC is the fine grained control you have over the bits of your website, and it all feels like you are still working on a website. Lets be [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working with ASP.NET MVC 2.0 for the last couple of months, 6 or so and the thing that I love the most about ASP.NET MVC is the fine grained control you have over the bits of your website, and it all feels like you are still working on a website. Lets be honest here for a moment, developing web applications with webforms feels unnatural and unwieldy and you always have this sense of it not being a &#8220;real&#8221; web application but rather some leaky abstraction of Windows Forms. ASP.NET MVC changed this perception a bit, by first dumping the whole page-life cycle and then by removing the whole page behind architecture. Instead you now have a very clear separation of concerns, with html being kept in views and your code is defined inside controllers and models. Controllers are small pieces of code that give views their content and you can specify whether a view is strongly typed or not, in which case when you use the Model keyword you gain access to a particular model&#8217;s properties or methods. The general rule is that controllers should be skinny and models should be fat. Models are the business logic of the application and contain items such as your interfaces and classes. Enough about what ASP.NET MVC is for now.</p>
<p>ASP.NET MVC 2 uses the Webform rendering engine and ASP.NET MVC 3 uses the Razor rendering engine. You can read more about the <a href="http://weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx" onclick="urchinTracker('/outgoing/weblogs.asp.net/scottgu/archive/2010/07/02/introducing-razor.aspx?referer=');">Razor view engine</a> on Scott Gu&#8217;s blog, but essentially it boils down to is the way in which dynamic content and html is rendered and how your view engine deals with it. </p>
<p>Today I started reading up on ASP.NET MVC 3 and Razor, starting <a href="http://weblogs.asp.net/scottgu/archive/2010/10/22/asp-net-mvc-3-layouts.aspx" onclick="urchinTracker('/outgoing/weblogs.asp.net/scottgu/archive/2010/10/22/asp-net-mvc-3-layouts.aspx?referer=');">here</a> because I wanted to get a better understanding of how layouts work in Razor and also how I could leverage some of its cool functionality specifically for a CMS. Before I continue discussing how I could see myself building a CMS using Razor, I want to define what I would want from a CMS and what I would want it to do. Consider this my requirement statement, my way of defining the nature and functionality of the CMS. </p>
<p>I want a CMS that is flexible enough to handle multiple page layouts without having to create static pages. In other words I want to create a CMS that allows me to add pages from scratch without having any static views in place. I just want to be able to create pages using different templates. So if my only view is the home view, then every subsequent page that I add will essentially be part of a ViewResult within the HomeController, and if pages are nested the ViewResult should reflect that. A page can have a parent or child page, nth levels deep. The basic workflow for adding a page to a CMS could be:</p>
<ol>
<li>Select a page Template</li>
<li>Select a layout</li>
<li>Populate regions within layout with content</li>
<li>Save the page</li>
</ol>
<p>Apart from this basic functionality the CMS should provide a way to integrate &#8220;datasets&#8221; or strongly typed data items into a page, style the data items and provide cascading pages if required without the CMS having to know anything about the data item it is cascading. If you have a product and it has several entities associated to it then you might want to create separate pages based on those entities, but then it means you have to specify the page and page layouts for the cascading items. It also depends on what type of layout that data item has. </p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save" onclick="urchinTracker('/outgoing/www.addtoany.com/share_save?referer=');"><img src="http://www.fremus.co.za/blog/wp-content/plugins/add-to-any/favicon.png" width="16" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.fremus.co.za/blog/2011/01/building-a-cms-with-asp-net-mvc-3-razor-conceptualisation/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WCF, ASP.NET Webforms, ASP.NET MVC and jQuery</title>
		<link>http://www.fremus.co.za/blog/2010/11/wcf-asp-net-webforms-asp-net-mvc-and-jquery/</link>
		<comments>http://www.fremus.co.za/blog/2010/11/wcf-asp-net-webforms-asp-net-mvc-and-jquery/#comments</comments>
		<pubDate>Wed, 10 Nov 2010 08:04:47 +0000</pubDate>
		<dc:creator>fr3dr1k</dc:creator>
				<category><![CDATA[AJAX]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Web Technologies]]></category>
		<category><![CDATA[jquery]]></category>
		<category><![CDATA[WCF]]></category>

		<guid isPermaLink="false">http://www.fremus.co.za/blog/?p=710</guid>
		<description><![CDATA[I haven&#8217;t written a technical article in a while but I thought I would write one that discusses AJAX calls with jQuery. Before I get into it I would like to reiterate some of my personal development objectives of late: Don&#8217;t do ANY UI manipulation in any of my server side API&#8217;s. The sole purpose [...]]]></description>
			<content:encoded><![CDATA[<p>I haven&#8217;t written a technical article in a while but I thought I would write one that discusses AJAX calls with jQuery. Before I get into it I would like to reiterate some of my personal development objectives of late:</p>
<ol>
<li>
              Don&#8217;t do ANY UI manipulation in any of my server side API&#8217;s. The sole purpose of any API within the applications I build is to deal with business layer logic and the data related to it. Ideally speaking I would want my API to return structured data which is easily transformed into a format for the client application using the API (e.g. JSON). I have had experiences within another development team in the recent past where the API returned HTML with the data and to say that this is a mess is understating the obvious &#8211; if you think about it quickly then you can understand the impact of one style or layout change will have on this approach. It also blurs your application in terms of its concerns and makes testing a problem. So ideally I dont want any UI logic in any of my API&#8217;s.
        </li>
<li>
The second objective I have is that all my UI for web applications must be handled with client-side scripts. Client side includes both static HTML, CSS and JavaScript, and in this instance I specifically refer to JavaScript and the handling of my API&#8217;s data using JSON, for which I use jQuery. The REST (:D) of this article is dedicated to the AJAX options available in an ASP.NET application.
</li>
</ol>
<p><strong>Dealing with AJAX in an ASP.NET Application</strong></p>
<p>Developing ASP.NET applications gives you two &#8220;frameworks&#8221; or &#8220;architectures&#8221; to work with:</p>
<ol>
<li>ASP.NET Webforms</li>
<li>ASP.NET MVC</li>
</ol>
<p>Notice that each architecture or framework uses the ASP.NET runtime which in turn runs on the .NET framework, and part of the .NET framework is the Common Language Runtime (CLR). People often think ASP.NET automatically refers to webforms. The difference between the architectures lies both in how it was designed and who it was designed for. Webforms was designed for Windows Forms developers working within the Visual Studio drag-and-drop environment and aimed to provide an abstraction of Windows Forms for the web. With webforms you could simply drag and drop controls onto a design surface and assign properties to the controls. The problem with webforms was that it required state management and to deal with the state management viewstate was created. Basically state management refers to a controls ability to retain its &#8220;value state&#8221; across postbacks. So if I created a simple label and set its text to &#8220;hello world&#8221; viewstate is used to retain that text value throughout the life of the rendered page. Webforms also introduced the concept of the Page Life Cycle, which exposed certain events at certain points of the page&#8217;s rendering process. The problem with viewstate is that the viewstate is inserted into your HTML pages which causes the page to bloat &#8211; so there is no clean markup. Viewstate totally goes against the grain of how the web works &#8211; being stateless.</p>
<p>ASP.NET MVC addresses some of the issues associated with webforms by using a mature and well known architectural pattern &#8211; Model-View-Controller, as used in Ruby-On-Rails. ASP.NET MVC does not use the page lifecycle for a start and it embraces the web&#8217;s statelessness instead of fighting it. The result is that you have no ViewState and this means that there is no HTML bloat and you also have complete control over your HTML.</p>
<p>There are a couple of ways to consume AJAX requests in ASP.NET but they fall into two categories:</p>
<ol>
<li>SOAP</li>
<li>REST</li>
</ol>
<p>In my previous development role I worked with guys that used SOAP to do AJAX requests and although this approach was good enough it was specifically aimed at ASMX web services which meant adding web references to your project. Needless to say adding these reference is a pain in the ass, because if a new method was added to a service you had to first update your reference before you could see the method. REST, however, addresses this issue by allowing you to make calls to URL&#8217;s, and not by adding any references. It also means that if a new method is created its available immediately. The remainder of this article is about consuming REST-like services in an ASP.NET application.</p>
<p>With my latest development effort I started out by using Page Methods in an ASP.NET Webform application. Why ASP.NET webforms you may ask? Well I wanted to focus on the business value and I just started out with Webforms without concerning myself too much with the technical side of things. Page methods implement a REST-like architecture and simply requires that you add a WebMethod attribute in your code-behind&#8217;s CS file like this:</p>
<pre name="code" class="csharp">
    [WebMethod]
    public static Dictionary<DateTime, List<MonthReport>> GetLastSixMonthReport()
</pre>
<p>You could then access the web method through jQuery like this (notice the Default.aspx/GetImportsLastSixMonths):</p>
<pre name="code" class="javascript">
    $.ajax({
        type: "POST",
        url: "Default.aspx/GetImportsLastSixMonths",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            var dict = msg.d;
            var html = '';
            $("#importsData").empty();
            html += dict;
            $("#importsData").append(html);
        }
    });
</pre>
<p>The main issue I have with this approach was that if I wanted to create a new web project I had to re-create the web methods &#8211; which is not ideal. So if I wanted to move this project over to a new MVC app I would have to recreate the methods. Based on this I decided to create a separate WCF project that could host all my methods and deliver them in a REST-JSON way. To get WCF to deliver JSON in a REST fashion you need to do two important things:</p>
<ul>
<li>Configure it</li>
<li>Add the appropriate Interface attributes</li>
</ul>
<p>Configuring a WCF service for JSON requires that you add an endpoint address to the service itself like this:</p>
<pre name="code" class="xml">
<endpoint address="ajaxEndpoint" behaviorConfiguration="AjaxBehaviour" binding="webHttpBinding" name="RESTEndpoint" contract="IMyInterface"/>
</pre>
<p>You also need to add an endPointBehavior like this:</p>
<pre name="code" class="xml".
			<endpointBehaviors>
				<behavior name="AjaxBehaviour">
					<webHttp/>
				</behavior>
			</endpointBehaviors>
</pre>
<p>In your service behaviours you need to set httpGetEnabled to true as well. I added this in my service class:</p>
<pre name="code" class="csharp">
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
</pre>
<p>In service contract I added the WebInvoke attribute to each method, like this:</p>
<pre name="code" class="csharp">
    [OperationContract]
    [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Wrapped, ResponseFormat = WebMessageFormat.Json)]
    ProductCollectionView[] GetProductCollectionViews();
</pre>
<p>Once I set this up I could access the JSON-enabled endpoint: http://localhost/LRB2CServiceLayer_v1/LRB2c.svc/ajaxEndpoint/GetProductCollectionViews and I would see the JSON. Notice that the JSON comes with a MethodNameResult as opposed to the &#8220;d&#8221; from the page methods. Consuming it uses a similar approach to the jQuery for page methods, except that you use a GET (which is a little dodgy):</p>
<pre name="code" class="javascript">
    $.ajax({
        type: "GET",
        url: "http://localhost/LRB2CServiceLayer_v1/LRB2c.svc/ajaxEndpoint/GetProductCollectionViews",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            var dict = msg["GetProductCollectionViewsResult"];
            var html = '';
            $("#importsData").empty();
            html += dict;
            $("#importsData").append(html);
        }
    });
</pre>
<p>I decided to convert the WCF service to a class library (DLL) instead because I had all kinds of issues with XSS because I ran the WCF service as a separate web application. The idea was that a WCF service was easily shared between web apps. I basically combined the class library with a MVC web app instead. A class library can just as easily be shared among multiple projects or web sites. The JSON that MVC returns is different to WCF and Webforms &#8211; it just returns the object, no indexer/key such as &#8220;d&#8221;. Getting MVC to return JSON is pretty straight forward:</p>
<pre name="code" class="csharp">
        [HttpPost]
        public JsonResult GetGetProductCollectionViews()
        {
        }
</pre>
<p>Of the three methods/technologies I described I like the ASP.NET MVC approach because:</p>
<ul>
<li>Its RESTful</li>
<li>The JSON result only contains the object(s)</li>
</ul>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save" onclick="urchinTracker('/outgoing/www.addtoany.com/share_save?referer=');"><img src="http://www.fremus.co.za/blog/wp-content/plugins/add-to-any/favicon.png" width="16" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.fremus.co.za/blog/2010/11/wcf-asp-net-webforms-asp-net-mvc-and-jquery/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Trying to turn a new development leaf</title>
		<link>http://www.fremus.co.za/blog/2010/06/trying-to-turn-a-new-leaf/</link>
		<comments>http://www.fremus.co.za/blog/2010/06/trying-to-turn-a-new-leaf/#comments</comments>
		<pubDate>Mon, 21 Jun 2010 12:24:09 +0000</pubDate>
		<dc:creator>fr3dr1k</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Application Development]]></category>
		<category><![CDATA[Agile]]></category>
		<category><![CDATA[WSF]]></category>

		<guid isPermaLink="false">http://www.fremus.co.za/blog/?p=642</guid>
		<description><![CDATA[I&#8217;m not sure development teams do the testing they are suppose to do, or follow the advice of what proponents of testing say you should do. As a matter of fact I know that most teams do not practice any form of formal testing, or rather make testing a key component of their development. Test [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m not sure development teams do the testing they are suppose to do, or follow the advice of what proponents of testing say you should do. As a matter of fact I know that most teams do not practice any form of formal testing, or rather make testing a key component of their development. Test Driven Development in an Agile scenario prescribes that you write code, write test code, test it and iterate if necessary. Essentially TDD forces you into a discipline of making sure your code works, which incidentally is one of the key objectives of an agile development methodology &#8211; you must always have a working portion of your code. In other words if you have to release code immediately then there should be code of sufficient working quality available to make everything work. That is my understanding anyway. </p>
<p>The reason I am looking at using agile as a development methodology is because I want to develop a commercial product using ASP.NET MVC and as <a href="http://haacked.com/archive/2007/12/07/tdd-and-dependency-injection-with-asp.net-mvc.aspx" onclick="urchinTracker('/outgoing/haacked.com/archive/2007/12/07/tdd-and-dependency-injection-with-asp.net-mvc.aspx?referer=');">Phil Haack says in this article</a>:</p>
<blockquote><p>Notice that at this point, we’re focusing on the behavior of our app first rather than focusing on the UI first. This is a stylistic difference between ASP.NET MVC and ASP.NET WebForms. Neither one is necessarily better than the other. Just a difference in approach and style.</p></blockquote>
<p>And from that I gather that ASP.NET MVC was designed to work well as a unit testing platform as well. I started about 3 weeks ago to formalise my development process and I started out by defining agile to have the following steps:</p>
<ul>
<li>Start off by Planning a work item</li>
<li>Do a requirements analysis of the work item and identify what you will need to do to get it working correctly</li>
<li>Design the code/program</li>
<li>An iteration then begins:
<ul>
<li>Write the code</li>
<li>Write a unit test</li>
<li>Do an acceptance test</li>
</ul>
</li>
</ul>
<p>I am having to change my development process though, because I intend to use Team Foundation Server (TFS) as my source control system, and I was thinking that maybe I need to consider using MSF (Microsoft Solution Framework) to drive my development process. MSF is integrated into TFS, and it essentially means that you can build applications and do source control within a development methodology. I started off <a href="http://search.microsoft.com/Results.aspx?q=microsoft+solution+framework+v4&#038;x=0&#038;y=0&#038;mkt=en-US&#038;FORM=QBME1&#038;l=1&#038;refradio=0&#038;qsc0=0" onclick="urchinTracker('/outgoing/search.microsoft.com/Results.aspx?q=microsoft+solution+framework+v4_038_x=0_038_y=0_038_mkt=en-US_038_FORM=QBME1_038_l=1_038_refradio=0_038_qsc0=0&amp;referer=');">looking for stuff on MSDN</a> and searched for this and came across <a href="http://search.microsoft.com/Results.aspx?q=microsoft+solution+framework+v4&#038;x=0&#038;y=0&#038;mkt=en-US&#038;FORM=QBME1&#038;l=1&#038;refradio=0&#038;qsc0=0" onclick="urchinTracker('/outgoing/search.microsoft.com/Results.aspx?q=microsoft+solution+framework+v4_038_x=0_038_y=0_038_mkt=en-US_038_FORM=QBME1_038_l=1_038_refradio=0_038_qsc0=0&amp;referer=');">this presentation</a>. From this presentation I understood that the agile process is structured a little differently to what I did in my initial process definition. Each iteration in a MSF consists of:</p>
<ul>
<li>Envision</li>
<li>Plan</li>
<li>Build</li>
<li>Stabilize</li>
<li>Deploy</li>
<li>Continuous</li>
</ul>
<p>Iterations occur at various steps and its up to the project manager to determine how many iterations occur. MSF also promotes a daily work cycle, which essentially makes sure that your code is of an acceptable standard. Essentially you check-in each day, make a build, make sure its an acceptable build and then you continue the develpment process within an iteration. This process repeats daily. Within the iteration cycle there are several other iterations which aim to achieve a pre-determined level of quality, based on planning of feature sets. The iterations also act as a mechanism to correct a project plan if there are deviations. The iteration is broken up into iteration cycles, with iteration 0 consisting of a project setup plan followed by a first iteration that involves planning, developing, testing and getting feedback followed by an nth number of iterations that involve planning, developing, testing and feedback. The last iteration is a set of nth iterations that involve developing, testing and releasing the product. You have to view these iterations as a set of &#8216;refinement&#8217; iterations, each iteration is intended to refine the solution. You also have to view these iterations in relation to the iteration steps mentioned above. In the powerpoint presentation they present a very cool view of the iterations as they happen. </p>
<h2>Iteration 0</h2>
<p>At the top they start off with the envision stage that includes the writing of a vision statement and the identification of personas within your system. Once that is defined you have to determine an iteration length. At the planning stage of the iteration you have to access/assess project progress, which is a continual thing I assume. Within the build stage you must start off by creating a scenario through brainstorming. You must also create a Quality of Service scenario through which you create a QoS. At this stage you must also refine the personas. The scenario that you created previously requires that you prioritise the scenario list, each with a scenario description. You need to prioritise QoS as well and write a QoS requirement. From the scenarios that have been written you need to create a solution architecture that partitions the system. You also need to storyboard the scenario, and develop a performance model. You also have to identify the security objectives, and then you need to test the scenario by defining a test approach. </p>
<p>On the next level you have to determine the interface. Does this mean the actual UI? You also need to plan an iteration at this stage by estimating a scenario or QoS. Then you need to develop a threat model. On the next level you need to plan an iteration around scheduling a scenario. From this you can develop an architectural prototype. You also need to plan an iteration around QoS and then create a infrastructure architecture. At the next level/step you plan an iteration around dividing the scenario into tasks, that make up a dev task which is then costed, and the same strategy is applied to QoS. </p>
<p>From the diagram in the powerpoint I assume that you can repeat as many iterations as you want.</p>
<h2>Iteration 1</h2>
<p>Iteration 1 includes writing a QoS test and writing a validation test for testing your scenario. It also includes doing a code check-in to your source control. It contains stages/levels that require you to write code for a development task, as well as creating an update of a unit test. It also covers fixing bugs:</p>
<ul>
<li>Reproducing the bug</li>
<li>Locating the bug cause</li>
<li>Deciding on a bug fix strategy</li>
<li>Reassign the bug</li>
<li>Create of Update unit test</li>
<li>Code the fix</li>
<li>Perform unit test</li>
</ul>
<p>Implementing a development task covers the following:</p>
<ul>
<li>Create of Update Unit Test</li>
<li>Write code for dev task</li>
<li>Perform Unit Test</li>
<li>Perform Code Analysis</li>
<li>Refactor code</li>
<li>Integrate Code Change</li>
</ul>
<p>After this stage there has to be a build and an accepted build. In the build there will be:</p>
<ul>
<li>Start a build</li>
<li>Verify a Build</li>
<li>Fix a build</li>
<li>Accept Build</li>
</ul>
<p>An accepted build will revolve around testing scenarios and in particular:</p>
<ul>
<li>Conducting an exploratory test</li>
<li>Select and run a test case</li>
<li>Open a bug</li>
</ul>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save" onclick="urchinTracker('/outgoing/www.addtoany.com/share_save?referer=');"><img src="http://www.fremus.co.za/blog/wp-content/plugins/add-to-any/favicon.png" width="16" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.fremus.co.za/blog/2010/06/trying-to-turn-a-new-leaf/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A case for ASP.NET MVC</title>
		<link>http://www.fremus.co.za/blog/2010/02/a-case-for-asp-net-mvc/</link>
		<comments>http://www.fremus.co.za/blog/2010/02/a-case-for-asp-net-mvc/#comments</comments>
		<pubDate>Mon, 01 Feb 2010 10:31:43 +0000</pubDate>
		<dc:creator>fr3dr1k</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>

		<guid isPermaLink="false">http://www.fremus.co.za/blog/?p=565</guid>
		<description><![CDATA[What is the case for ASP.NET MVC? Lets forget the architecture for a minute and just focus on what it offers me as the developer, or rather what features do the other ASP.NET technologies offer that I do not like using. For starters web forms are &#8216;heavy&#8217; and not as lightweight as ashx files. ASHX [...]]]></description>
			<content:encoded><![CDATA[<p>What is the case for ASP.NET MVC? Lets forget the architecture for a minute and just focus on what it offers me as the developer, or rather what features do the other ASP.NET technologies offer that I do not like using. For starters web forms are &#8216;heavy&#8217; and not as lightweight as ashx files. ASHX files are lighter because they do not have all the overheads a webform has, but they lack HTML support. The HTML support in webforms sucks because it does not render clean HTML, the tag id&#8217;s for instance, and viewstate are examples of &#8216;unclean&#8217; html. For HTML support in a ashx file you will need to write some code that reads HTML and renders it, plus you will have to do some string manipulation somewhere to place content in the HTML. This seems a bit cumbersome to me. Why cant I have my HTML generated without having to do something like that, but also without worrying about clean HTML. ASP.NET MVC renders clean HTML. ASP.NET MVC Controllers are also available through XmlHttpRequests, making it easy to implement AJAX functionality.</p>
<p>Two reasons to use ASP.NET MVC:</p>
<ul>
<li>Clean HTML</li>
<li>Controllers can be called from JavaScript</li>
</ul>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save" onclick="urchinTracker('/outgoing/www.addtoany.com/share_save?referer=');"><img src="http://www.fremus.co.za/blog/wp-content/plugins/add-to-any/favicon.png" width="16" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.fremus.co.za/blog/2010/02/a-case-for-asp-net-mvc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A strategy for using AJAX on ur website</title>
		<link>http://www.fremus.co.za/blog/2009/02/a-strategy-for-using-ajax-on-ur-website/</link>
		<comments>http://www.fremus.co.za/blog/2009/02/a-strategy-for-using-ajax-on-ur-website/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 16:55:55 +0000</pubDate>
		<dc:creator>fr3dr1k</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[AJAX]]></category>

		<guid isPermaLink="false">http://www.fremus.co.za/blog/?p=351</guid>
		<description><![CDATA[I have been thinking a lot recently about the use (or abuse) of AJAX on a website and it made me think of a strategy to try and adopt. Like all technological things it makes sense to understand the overall business goal first and then to proceed to the next step. It also makes sense [...]]]></description>
			<content:encoded><![CDATA[<p>I have been thinking a lot recently about the use (or abuse) of AJAX on a website and it made me think of a strategy to try and adopt. Like all technological things it makes sense to understand the overall business goal first and then to proceed to the next step. It also makes sense not to focus too much effort in one area and neglect others. For instance, too much AJAX and JavaScript will create bigger and bigger .js files, which require more and more maintenance to try and keep small. On the other hand you cannot, not use AJAX, on or in your web applications these days. So whats the best strategy? Well I think you need to understand your business goals, and make sure that what you want to achieve can be achieved. Consistency is often something to strive for in this context, because being consistent is often far tougher than making one or two good impressions. The User Interface (UI) must be consistent throughout any application, rather than be too elaborate. </p>
<p>So to come back to my strategy for using AJAX in web applications, I think an approach I am going to try is to divide navigation into two classes:<br />
*Website navigation<br />
*Page level navigation</p>
<p>Website navigation will generally allow for &#8220;postbacks&#8221; whereas page level navigation will allow for actions that are very specific for that page. The MVC framework provides a structure that supports this strategy. Your views act as your &#8220;postbacks&#8221; and the actual views themselves are where the activity takes place. Postbacks in this instance refers to the flicker effect you get when you click on links, whereas AJAX allow for a smoother effect. </p>
<p>The other bit of strategy I would like to think about is processing the results from datasources through AJAX. At the moment I am developing web applications where the web services return HTML strings, and the JavaScript simple ends up displaying it. I feel that this approach is messy and does not allow for a clear and contextualised view of your system. There must be an approach that creates good quality AJAX that can interact with server side code. I am looking for an approach that will make it easier to develop and implement my classes. I love the classical object design approach because I like things organised that way.</p>
<p><a class="a2a_dd addtoany_share_save" href="http://www.addtoany.com/share_save" onclick="urchinTracker('/outgoing/www.addtoany.com/share_save?referer=');"><img src="http://www.fremus.co.za/blog/wp-content/plugins/add-to-any/favicon.png" width="16" height="16" alt="Share/Bookmark"/></a> </p>]]></content:encoded>
			<wfw:commentRss>http://www.fremus.co.za/blog/2009/02/a-strategy-for-using-ajax-on-ur-website/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

