Abstractions can also put you in Trouble

We all have enjoyed the beauty of abstracting out functionality, so that it simplifies the underlying complexity. Sometimes it can come back and hit you on the forehead like a boomerang if we don’t know what is going underneath those hidden layers.

Recently it happened to me with the LINQ provider. If you have a data source then you can build your own Query provider on top of it, so that the users can access your data using the LINQ statements without understand how it is fetched.

For e.g. Linq2Twitter it provides the IQueryable interface which you can use fetch the twitter API without understanding the REST API’s exposed by the Twitter.

Similarly Ayende has created a Linq provider for NHibernate (NHibernate.Linq) which hides complexities of writing Criteria API’s.

This is what happened to me – we had a repository method which is using the NHibernate.Linq and it returned an IQueryable interface of domain model.

Like to the below code(only an example, this is not from the actual codebase itself)

1
2
3
4
5
public IQueryable<Customer> QueryableCustomers()
{
session = SessionFactory.OpenSession();
return session.Linq<Customer>().AsQueryable();
}

In the consumer part (Action method in the controller), we are filtering the customer with a name containing particular string using the Contains method

this.dataProvider.QueryableCustomers().Where(x => x.Name.Contains("custo")).ToList();

Everything worked as expected, but one day the filtering stopped working, I couldn’t figure it out initially, but when I looked into the QueryableCustomers() method, it has been changed to something like this

1
2
3
4
5
public IQueryable<Customer> QueryableCustomers()
{
session = SessionFactory.OpenSession();
return session.Linq<Customer>().ToList().AsQueryable();
}

Not much difference in the code wise, but internally the earlier code will filter the customers using the SQL statement by adding a where clause to the SQL it generated and later one will fetch all the customers from the DB and filter that result using the LINQ on objects.

SQL generated for initial code

1
2
3
4
5
6
7
8
9
SELECT
this_.Id as Id0_0_,
this_.Name as Name0_0_,
this_.Address as Address0_0_
FROM
Customer this_
WHERE
this_.Name like @p0;
@p0 = '%custo%'

After code change, the query generated SQL was

1
2
3
4
5
6
SELECT
this_.Id as Id0_0_,
this_.Name as Name0_0_,
this_.Address as Address0_0_
FROM
Customer this_

By now you might have realized the reason why the I didn’t get the expected result from the new code change – if not here is the explanation, Contains in the earlier code is translated by the NH LINQ provider to a where clause which is case insensitive by default unless you have set any specific Collation in the database or on the column itself but in the other hand new code returned a collection of Customer itself, then we applied String.Contains on the Name property which is case sensitive.

My point here is - we can’t blindly believe in the abstractions provided by anyone without understanding what is happening underneath.

How to Move Directories Across SVN Repositories

Recently we were restructuring our project repositories, where I had to move a project from it’s own repository to another repository.

When do a move under SVN you need to make sure that the history is not lost, so I will explain two common scenarios and how you could do the SVN move

###Scenario 1 - Moving files or directories with in a SVN repository

Below is a screen shot of my existing repository and I want to move the configuration directory to the project directory without loosing the history.

SVN repository structure

First of of all this will work only for the versioned items, so please commit your changes to the directory you want to move before doing this. The steps explained below assumes that you are using Tortoise SVN

Here are the steps

  1. Right click on the directory you want to move
  2. Drag and drop on to the directory where you want to move this.
  3. Choose the SVN Mover Versioned item(s) here item from the context menu.
    Context Menu with move
  4. Now commit the changes back to the repository.

Don’t forget to uncheck Stop on copy/rename option in the Log messages dialog if you are trying to see the history of the moved directory.

Move configuration

###Scenario 2 – Moving directories across SVN repositories

In this case I want to move Project directory to another repository Repo2

The first technique I have mentioned will work only if the source and target are under same repository, but in some cases you have to move the directories across different SVN repositories. This cannot be done from a SVN client slike TortoiseSVN, you need o use the utilities that comes with SVN.

Follow these steps

  1. Dump the repository to a file using the svnadmin tool – e.g. svnadmin dump c:\Repositories\Repo1 > Repo1file
  2. Now load the dumped filed into the target repository – e.g. svnadmin load c:\Repositories\Repo2 < Repo1file

Here is the full syntax for svnadmin tool

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ svnadmin dump --help
dump: usage: svnadmin dump REPOS_PATH [-r LOWER[:UPPER] ] [--incremental]

Dump the contents of filesystem to stdout in a 'dumpfile'
portable format, sending feedback to stderr. Dump revisions
LOWER rev through UPPER rev. If no revisions are given, dump all
revision trees. If only LOWER is given, dump that one revision tree.
If --incremental is passed, then the first revision dumped will be
a diff against the previous revision, instead of the usual fulltext.

Valid options:
-r [--revision] arg : specify revision number ARG (or X:Y range)
--incremental : dump incrementally
--deltas : use deltas in dump output
-q [--quiet] : no progress (only errors) to stderr

How to Move Directories Across SVN Repositories

Recently we were restructuring our project repositories, where I had to move a project from it’s own repository to another repository.

When do a move under SVN you need to make sure that the history is not lost, so I will explain two common scenarios and how you could do the SVN move

###Scenario 1 - Moving files or directories with in a SVN repository

Below is a screen shot of my existing repository and I want to move the configuration directory to the project directory without loosing the history.

SVN repository structure

First of of all this will work only for the versioned items, so please commit your changes to the directory you want to move before doing this. The steps explained below assumes that you are using Tortoise SVN

Here are the steps

  1. Right click on the directory you want to move
  2. Drag and drop on to the directory where you want to move this.
  3. Choose the SVN Mover Versioned item(s) here item from the context menu.
    Context Menu with move
  4. Now commit the changes back to the repository.

Don’t forget to uncheck Stop on copy/rename option in the Log messages dialog if you are trying to see the history of the moved directory.

Move configuration

###Scenario 2 – Moving directories across SVN repositories

In this case I want to move Project directory to another repository Repo2

The first technique I have mentioned will work only if the source and target are under same repository, but in some cases you have to move the directories across different SVN repositories. This cannot be done from a SVN client slike TortoiseSVN, you need o use the utilities that comes with SVN.

Follow these steps

  1. Dump the repository to a file using the svnadmin tool – e.g. svnadmin dump c:\Repositories\Repo1 > Repo1file
  2. Now load the dumped filed into the target repository – e.g. svnadmin load c:\Repositories\Repo2 < Repo1file

Here is the full syntax for svnadmin tool

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ svnadmin dump --help
dump: usage: svnadmin dump REPOS_PATH [-r LOWER[:UPPER] ] [--incremental]

Dump the contents of filesystem to stdout in a 'dumpfile'
portable format, sending feedback to stderr. Dump revisions
LOWER rev through UPPER rev. If no revisions are given, dump all
revision trees. If only LOWER is given, dump that one revision tree.
If --incremental is passed, then the first revision dumped will be
a diff against the previous revision, instead of the usual fulltext.

Valid options:
-r [--revision] arg : specify revision number ARG (or X:Y range)
--incremental : dump incrementally
--deltas : use deltas in dump output
-q [--quiet] : no progress (only errors) to stderr

Stay Away from Request.Url

The title might be misleading but I will explain why we shouldn’t use the Request.Url in any asp.net application directly.

If you are writing an web application and you don’t know the environment of the server where it is getting deployed, then it is better not to use Request.Url it directly.

This blog is running on a home grown blog engine, which is written using asp.net MVC 3. For implementing some of the functionalities like generating sitemap.xml I had to get the root of the url(i.e. without any path). So I used the Request.Url.GetLeftPart(UriPartial.Authority) method and it worked perfectly on my local machine even when it is deployed my local machine IIS server. When I deployed my blog engine to Appharbor environment, the generated sitemap.xml has a URL with port number like www.rajeeshcv.com:4566 instead of just www.rajeeshcv.com.

###Why?

After googling for some time I came across the solution posted Appharbor knowledge base - workaround for generating absolute urls without port number. In their environment there are load balancers which sits in front on the webserver, which uses a specific port number for contacting the server where the application is running. Below is a simple pictorial representation of that

Network with load balancer

So whenever we try to get Request.Url, application will get the actual request Url received by that webserver, which will have the port number also.

###How to solve it

Appharbor has provided a code snippet in the same article but it didn’t worked for me, I was still getting port number in the generated Url. My assumption is that, there is condition check for ignoring the local request so that it will work correctly in the local development environment.

1
2
3
4
if (httpContext.Request.IsLocal)
{
uriBuilder.Port = httpContext.Request.Url.Port;
}

According to the MSDN documentation

The IsLocal property returns true if the IP address of the request originator is 127.0.0.1 or if the IP address of the request is the same as the server’s IP address.

In my case I think IsLocal was true (I really don’t the exact reason!!!). So instead of using the appharbor code snippet I came across a code from FunnelWeb which does the same (HttpRequestExtensions.cs)

Here is my version of that code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/// <summary>
/// Environments the specific request URL.
/// </summary>
/// <param name="request">The request.</param>
/// <returns></returns>
/// <remarks>
/// Code from FunnelWeb: https://bitbucket.org/TheBlueSky/funnelweb/src/b64c74f361d3/src/FunnelWeb/Utilities/HttpRequestExtensions.cs
/// </remarks>
public static Uri EnvironmentSpecificRequestUrl(this HttpRequestBase request)
{

UriBuilder hostUrl = new UriBuilder();
string hostHeader = request.Headers["Host"];

if (hostHeader.Contains(":"))
{
hostUrl.Host = hostHeader.Split(':')[0];
hostUrl.Port = Convert.ToInt32(hostHeader.Split(':')[1]);
}
else
{
hostUrl.Host = hostHeader;
hostUrl.Port = -1;
}

Uri url = request.Url;
UriBuilder uriBuilder = new UriBuilder(url);

if (String.Equals(hostUrl.Host, "localhost", StringComparison.OrdinalIgnoreCase) || hostUrl.Host == "127.0.0.1")
{
// Do nothing
// When we're running the application from localhost (e.g. debugging from Visual Studio), we'll keep everything as it is.
// We're not using request.IsLocal because it returns true as long as the request sender and receiver are in same machine.
// What we want is to only ignore the requests to 'localhost' or the loopback IP '127.0.0.1'.
return uriBuilder.Uri;
}

// When the application is run behind a load-balancer (or forward proxy), request.IsSecureConnection returns 'true' or 'false'
// based on the request from the load-balancer to the web server (e.g. IIS) and not the actual request to the load-balancer.
// The same is also applied to request.Url.Scheme (or uriBuilder.Scheme, as in our case).
bool isSecureConnection = String.Equals(request.Headers["X-Forwarded-Proto"], "https", StringComparison.OrdinalIgnoreCase);

if (isSecureConnection)
{
uriBuilder.Port = hostUrl.Port == -1 ? 443 : hostUrl.Port;
uriBuilder.Scheme = "https";
}
else
{
uriBuilder.Port = hostUrl.Port == -1 ? 80 : hostUrl.Port;
uriBuilder.Scheme = "http";
}

uriBuilder.Host = hostUrl.Host;

return uriBuilder.Uri;
}

###Conclusion

IMHO this is a limitation with .Net framework itself because here we have to modify the behaviour of the framework class to achieve what we really want . If there is way in which the IIS web server can detect the topology on which it is running, then the HttpRequest.Url could be implemented correctly. So that the developer need not to worry about the deployment scenarios(at least in this simple case).

Stay Away from Request.Url

The title might be misleading but I will explain why we shouldn’t use the Request.Url in any asp.net application directly.

If you are writing an web application and you don’t know the environment of the server where it is getting deployed, then it is better not to use Request.Url it directly.

This blog is running on a home grown blog engine, which is written using asp.net MVC 3. For implementing some of the functionalities like generating sitemap.xml I had to get the root of the url(i.e. without any path). So I used the Request.Url.GetLeftPart(UriPartial.Authority) method and it worked perfectly on my local machine even when it is deployed my local machine IIS server. When I deployed my blog engine to Appharbor environment, the generated sitemap.xml has a URL with port number like www.rajeeshcv.com:4566 instead of just www.rajeeshcv.com.

###Why?

After googling for some time I came across the solution posted Appharbor knowledge base - workaround for generating absolute urls without port number. In their environment there are load balancers which sits in front on the webserver, which uses a specific port number for contacting the server where the application is running. Below is a simple pictorial representation of that

Network with load balancer

So whenever we try to get Request.Url, application will get the actual request Url received by that webserver, which will have the port number also.

###How to solve it

Appharbor has provided a code snippet in the same article but it didn’t worked for me, I was still getting port number in the generated Url. My assumption is that, there is condition check for ignoring the local request so that it will work correctly in the local development environment.

1
2
3
4
if (httpContext.Request.IsLocal)
{
uriBuilder.Port = httpContext.Request.Url.Port;
}

According to the MSDN documentation

The IsLocal property returns true if the IP address of the request originator is 127.0.0.1 or if the IP address of the request is the same as the server’s IP address.

In my case I think IsLocal was true (I really don’t the exact reason!!!). So instead of using the appharbor code snippet I came across a code from FunnelWeb which does the same (HttpRequestExtensions.cs)

Here is my version of that code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/// <summary>
/// Environments the specific request URL.
/// </summary>
/// <param name="request">The request.</param>
/// <returns></returns>
/// <remarks>
/// Code from FunnelWeb: https://bitbucket.org/TheBlueSky/funnelweb/src/b64c74f361d3/src/FunnelWeb/Utilities/HttpRequestExtensions.cs
/// </remarks>
public static Uri EnvironmentSpecificRequestUrl(this HttpRequestBase request)
{

UriBuilder hostUrl = new UriBuilder();
string hostHeader = request.Headers["Host"];

if (hostHeader.Contains(":"))
{
hostUrl.Host = hostHeader.Split(':')[0];
hostUrl.Port = Convert.ToInt32(hostHeader.Split(':')[1]);
}
else
{
hostUrl.Host = hostHeader;
hostUrl.Port = -1;
}

Uri url = request.Url;
UriBuilder uriBuilder = new UriBuilder(url);

if (String.Equals(hostUrl.Host, "localhost", StringComparison.OrdinalIgnoreCase) || hostUrl.Host == "127.0.0.1")
{
// Do nothing
// When we're running the application from localhost (e.g. debugging from Visual Studio), we'll keep everything as it is.
// We're not using request.IsLocal because it returns true as long as the request sender and receiver are in same machine.
// What we want is to only ignore the requests to 'localhost' or the loopback IP '127.0.0.1'.
return uriBuilder.Uri;
}

// When the application is run behind a load-balancer (or forward proxy), request.IsSecureConnection returns 'true' or 'false'
// based on the request from the load-balancer to the web server (e.g. IIS) and not the actual request to the load-balancer.
// The same is also applied to request.Url.Scheme (or uriBuilder.Scheme, as in our case).
bool isSecureConnection = String.Equals(request.Headers["X-Forwarded-Proto"], "https", StringComparison.OrdinalIgnoreCase);

if (isSecureConnection)
{
uriBuilder.Port = hostUrl.Port == -1 ? 443 : hostUrl.Port;
uriBuilder.Scheme = "https";
}
else
{
uriBuilder.Port = hostUrl.Port == -1 ? 80 : hostUrl.Port;
uriBuilder.Scheme = "http";
}

uriBuilder.Host = hostUrl.Host;

return uriBuilder.Uri;
}

###Conclusion

IMHO this is a limitation with .Net framework itself because here we have to modify the behaviour of the framework class to achieve what we really want . If there is way in which the IIS web server can detect the topology on which it is running, then the HttpRequest.Url could be implemented correctly. So that the developer need not to worry about the deployment scenarios(at least in this simple case).

New Outlook – Rolling out My Own Blog Engine

For the last couple of years I was using wordpress as my blogging platform, it is an awesome framework but finally I decided to move away from it and created my own blog engine(Rhyble), on which this blog is running now.

Rhyble is built using Asp.Net MVC3, NHiberanate and it is running Appharbor

You might ask why I want reinvent the wheel again because we have many blog engines available today. Jeff Atwood answered that question here - Why does every man and his dog want to code a blogging engine?

These were my objectives when I started creating Rhyble

  1. Focus on the most important functionalities, doesn’t want to create another wordpress with truck full of unwanted things
  2. Improve the performance. Now I have YSlow rating of 94 compared to 65
    image
  3. I didn’t wanted to go through the existing blog engines code base, which is more time consuming than creating a new one

YSlow previous and current ratings

More over it is a nice feeling if you have something you own. Now I have platform of my own and next things should be blogging frequently.

That’s it for the day.

New Outlook – Rolling out My Own Blog Engine

For the last couple of years I was using wordpress as my blogging platform, it is an awesome framework but finally I decided to move away from it and created my own blog engine(Rhyble), on which this blog is running now.

Rhyble is built using Asp.Net MVC3, NHiberanate and it is running Appharbor

You might ask why I want reinvent the wheel again because we have many blog engines available today. Jeff Atwood answered that question here - Why does every man and his dog want to code a blogging engine?

These were my objectives when I started creating Rhyble

  1. Focus on the most important functionalities, doesn’t want to create another wordpress with truck full of unwanted things
  2. Improve the performance. Now I have YSlow rating of 94 compared to 65
    image
  3. I didn’t wanted to go through the existing blog engines code base, which is more time consuming than creating a new one

YSlow previous and current ratings

More over it is a nice feeling if you have something you own. Now I have platform of my own and next things should be blogging frequently.

That’s it for the day.

Web Usability – Avoid an Extra Page Load with OpenSearch

Now a days most of the websites, blogs or any applications that are on internet will have a search functionality which is great!!!. Before the Omnibox concept was introduced by google chrome, if we want to search something in google, as a user I need to go to www.google.com and type the search query. After the introduction of Omnibox, user don’t need to open the google website instead you could do the search from the address bar itself. From the usability point of view, it is a great functionality IMHO.

From the point of google search application, they have done it smartly. As a web developer how could you provide the same usability feature to your own website. Some of the website I frequently visits has done like this.

StackOverflow Opensearch

If you are in google chrome, after you type the stackoverflow.com a message will be displayed on the address bar saying that Press Tab to search Stack Overflow. If you press tab, you can directly type the search query in the address bar itself and pressing enter will show the results. This basically allows you to do a quick search, instead of going to the website and finding the search box and pressing search button(a long process is it? Smile)

Recently I was working on a hobby project called ifscfinder , which is a website were you could search for a Indian Finacial System Code of any banks in India. It simply provide a search box where user could enter the Bank/Branch name and it will list the banks that matches the query. So I wanted to have the same feature like stackoverflow in my ifscfinder too.

After googling for sometime, I found about the opensearch which helps to achieve this functionality. You could read more about opensearch from here http://www.opensearch.org

What I had do was, create an xml file(OpenSearch description document), it will have URL format which needs to be called when user enter a search query. ifscfinder xml file looks like this

1
2
3
4
5
6
7
8
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName>IFSC Finder</ShortName>
<Description>Search IFSC: Find Indian Financial System Code of a Bank</Description>
<InputEncoding>UTF-8</InputEncoding>
<Url type="text/html"
template="http://ifscfinder.apphb.com/Search?q={searchTerms}"/>
</OpenSearchDescription>

After this is created, I upload it the website. In order for the browser to sense whether my website opensearch, I had to add link tag to the head element

<link rel="search" type="application/opensearchdescription+xml" title="IFSCFinder.com" href="/opensearchdescription.xml" />

With this ifscfinder has got a nice quick search option in google chrome

ifscfinder opensearch

Firefox also detect the opensearch , which mean you could add this site to the search engine list in firefox

Firefox Opensearch

IE9 doesn’t care about this at all(don’t know why!!!)

Web Usability – Avoid an Extra Page Load with OpenSearch

Now a days most of the websites, blogs or any applications that are on internet will have a search functionality which is great!!!. Before the Omnibox concept was introduced by google chrome, if we want to search something in google, as a user I need to go to www.google.com and type the search query. After the introduction of Omnibox, user don’t need to open the google website instead you could do the search from the address bar itself. From the usability point of view, it is a great functionality IMHO.

From the point of google search application, they have done it smartly. As a web developer how could you provide the same usability feature to your own website. Some of the website I frequently visits has done like this.

StackOverflow Opensearch

If you are in google chrome, after you type the stackoverflow.com a message will be displayed on the address bar saying that Press Tab to search Stack Overflow. If you press tab, you can directly type the search query in the address bar itself and pressing enter will show the results. This basically allows you to do a quick search, instead of going to the website and finding the search box and pressing search button(a long process is it? Smile)

Recently I was working on a hobby project called ifscfinder , which is a website were you could search for a Indian Finacial System Code of any banks in India. It simply provide a search box where user could enter the Bank/Branch name and it will list the banks that matches the query. So I wanted to have the same feature like stackoverflow in my ifscfinder too.

After googling for sometime, I found about the opensearch which helps to achieve this functionality. You could read more about opensearch from here http://www.opensearch.org

What I had do was, create an xml file(OpenSearch description document), it will have URL format which needs to be called when user enter a search query. ifscfinder xml file looks like this

1
2
3
4
5
6
7
8
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns="http://a9.com/-/spec/opensearch/1.1/">
<ShortName>IFSC Finder</ShortName>
<Description>Search IFSC: Find Indian Financial System Code of a Bank</Description>
<InputEncoding>UTF-8</InputEncoding>
<Url type="text/html"
template="http://ifscfinder.apphb.com/Search?q={searchTerms}"/>
</OpenSearchDescription>

After this is created, I upload it the website. In order for the browser to sense whether my website opensearch, I had to add link tag to the head element

<link rel="search" type="application/opensearchdescription+xml" title="IFSCFinder.com" href="/opensearchdescription.xml" />

With this ifscfinder has got a nice quick search option in google chrome

ifscfinder opensearch

Firefox also detect the opensearch , which mean you could add this site to the search engine list in firefox

Firefox Opensearch

IE9 doesn’t care about this at all(don’t know why!!!)

MVC - Rendering View Elements in a Specified Order

In my current project, I had to render elements in the view based on a setting provided by the model(basically it is a configurable thing). Few clients need view element to be rendered in a particular order and few others in a different way. What we did was, saved this elements order in a settings file which could be changed based on the clients. Then created an extension to render this based on the order.

This is what was I was trying to explain. for Client 1 the Login section to be displayed first followed by Password reminder section

Client 1 requirement

For Client 2 , these sections needs be ordered differently

Client 2 requirement

In order to achieve this, I came up with an HtmlHelper extension

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
/// <summary>
/// Renders the render items in the provided sequence order.
/// </summary>
/// <param name="htmlHelper">The HTML helper which is extended.</param>
/// <param name="sequenceOrder">The order in which items to be rendered. Sequence starts at an index of 0.</param>
/// <param name="renderItems">The items to be rendered in order.</param>
/// <remarks>
/// Values in the sequence order should match with the total number of render items.
/// Invalid sequnce numbers are ignored.
/// </remarks>
public static void OrderBy(this HtmlHelper htmlHelper, int[] sequenceOrder, params Action<HtmlHelper>[] renderItems)
{
if (sequenceOrder != null && renderItems != null)
{
foreach (var sequnce in sequenceOrder)
{
// CHeck whether the sequence is with inthe bounds
if (sequnce < renderItems.Length && sequnce >= 0)
{
renderItems[sequnce].Invoke(htmlHelper);
}
}
}
else if (renderItems != null)
{
// If the sequence order is not provided, render it in normal order in which items are declared.
foreach (var renderItem in renderItems)
{
renderItem.Invoke(htmlHelper);
}
}
else
{
// Do Nothing
}
}

In the view, you could do

1
2
3
4
5
6
7
<% Html.OrderBy(this.Model.LoginDisplayOrder, (html) => { %>
<div class="container"></div>
<% Html.RenderPartial("LoginSection", this.Model); %>
<% }, (html) => { %>
<div class="container"></div>
<% Html.RenderPartial("ReminderPassword", this.Model); %>
<% }); %>

Here Model.LoginDisplayOrder is just an array of integers in which the items to be rendered.

Hope this will help.