OJ Develops

Thoughts, tips, and tricks on software development. .NET | C# | Azure

Creating Custom Html Helper Methods

21 November 2015

HTML helper methods are used in Razor views to generate HTML markup in a strongly-typed, C-sharpy way. An example is `@Html.LabelFor(m => m.Name)`, which is used in a strongly-typed view whose model has a Name property. This will generate a label element with the appropriate display name. In this post we will learn how to create a custom HTML helper.

Read More

Create Meaningful Classes

08 November 2015

In a previous post I talked about the importance of good naming when writing code. The title of that post is "Don't Make Me Think... About Your Code". This post will talk about meaningful classes and can be considered as an addition to the "writing code" series.

Read More

AngularJS and SEO

26 September 2015

There is no doubt that JavaScript MVC / MVVM frameworks such as AngularJS provide better experiences for both developers and users alike. However, there are some caveats that we should be aware of when using this framework. Specifically, search engines might not be able to read the content in our applications if we are using the data binding features provided by these frameworks. In this post I will compare two scenarios - one using server-side data binding and one using client-side data binding and talk about their SEO implications.

Read More

Remove Custom Headers From Your ASP.NET MVC Project

19 September 2015

Whenever we start with a new ASP.NET MVC project, the tendency is to use one of the templates offered by Visual Studio. The template goes a long way in getting us started with our project. However one thing that the template does not do is remove the HTTP headers that are related to ASP.NET and MVC. Today we are going to look at those and how and why to remove them.

Read More

Using AutoMapper in Entity Framework Projections

12 September 2015

AutoMapper is a wonderful tool that lets us convert one class to another using fluently-defined configurations. It is useful when there is a need for multiple mappings, such mappings from persistence model classes to domain model classes or mapping from domain model classes to viewmodels. In this post we are going to look at how to use AutoMapper with Entity Framework for projections.

Read More

Converting an ASP.NET View to a String

15 March 2015

Sometimes you would like to get the contents of a view and store it in a string rather than render it as HTML. An example of this is if you want to compose HTML emails and you want to harness the power of the ASP.NET MVC infrastructure (which includes layouts, partial views, and models). In this post I will show you how to store rendered View content in a string.

Read More

Separating Business Rules from Data Access

01 March 2015

Business rules can be mixed into data access code. This scenario is a violation of the Single Responsibility Principle, because the data access class would have to change if the business rules change. In this post I will show you how to separate the business rules from the data access code.

Read More

Adding an SQL Azure Linked Server

10 January 2015

When adding an SQL Azure Linked Server through SSMS, you will encounter an error if you go through the normal way (Server Objects > Linked Servers > New Linked Server). That is because the New Linked Server wizard does not allow you to specify the catalog name if the chosen Server Type is SQL Server, which should be chosen when adding an SQL Azure Linked Server. To accomplish this, the stored procedure sp_addlinkedserver should be used.

Read More