Ellipsis on long text in the table.

Sometimes you would like to shorten your long text in the HTML table. Here is the way to go with css and jQuery: css:

<table>
  <tr>
    <td class="ellipsis">
      Some very long text that you would like to be shortened
    </td>
  </tr>
</table>

CSS:

td.ellipsis {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 300px
}

jQuery:

$('.ellipsis').each(function (index) {
    var $this = $(this);
    var titleVal = $this.text();
    if (titleVal != '') {
        $this.attr('title', $.trim(titleVal));
    }
});

ScriptDB

A great and simple project that saves a lot of time for SQL Server Development: ScriptDB. Unfortunately have not been updated for 4 years already. And out of the box does not work with SQL Server 2008 and SQL Server 2012.

I have took the liberty to compile the project (thanks to the open-source!) against the newer libraries and now it works for SQL Server 2008 and SQL Server 2012.
Enjoy!

ScriptDB for SQL Server 2008 and 2012

Set Validation error in ASP.Net MVC Controller

Every time I need to set a validation error in a controller, I need to look up how to do this. But it is very simple. So I’ll just write it down here, for future reference: In controller do:

ModelState.AddModelError("FieldName", "Error message for User");

If you leave FieldName blank, the error will come up in validation summary. In a view you’ll have to do this:

@Html.ValidationSummary(true) // for the whole model
@Html.ValidationMessageFor(m => m.UserName) // for individual model field

Configure IIS to use a certain user account to work

The problem I faced with with Drupal installation – I could not give right permissions to the upload folder to store files as required.
I had the solution for IIS6, but IIS7 have different user set-up, so new solution was required.
After some fiddling about, I stumbled across this solution:

  1. Create a normal Windows user for your Drupal install. Create a password too.
  2. Create an application pool for your Drupal install. Set the application pool’s identity to your windows user: in IIS7 double click the new application pool and then Advanced Settings -> Process Model -> Identity
  3. Set your website to use that application pool
  4. In web-site go to Authentication -> Anonymous Authentication -> Edit -> Set to Application pool identity:
  5. Give (or deny) the Windows user full control to the sites\default directory

So, what all this does is give the Drupal install privilege isolation. It can only write files in the sites\default directory, but not your settings.php. It can still create needed cache file, uploads, etc.

Unable to set break point for debugging in Visual Studio

Getting “The breakpoint will not currently be hit. No symbols have been loaded for this document.” in Visual studio whenever you try to debug?
There are a million solutions out there and every time it is a different issue.

Here is one way of sorting things out in VS2012:

Go to Tools -> Options -> Debugging -> Symbols.
Hit Empty Symbol Cache and select All Modules Unless Excluded.

Possibly will need to restart VS. And should work.

MVC3: Form submitted only by GET method, without specifying controller and action

Sometimes in ASP.Net MVC you need to submit a form that will always go by GET method. But standard BeginForm() function does not have an override that does not requires specifying Controller and Action where you would like to submit the form back to. And sometimes you don’t want to specify where the form to go to, cause the same form can go into multiple controllers (think of a partial view). And default BeginForm() submits only by POST. So there is no default way to say I want to submit form by POST to wherever the form has came from.

I had to poke through MVC source code to figure out how to do what I want, and keep all the parameters and not mess up any paths. Here you go:

public static MvcForm BeginForm(this HtmlHelper htmlHelper, FormMethod method)
{
    var rd = htmlHelper.ViewContext.HttpContext.Request.RequestContext.RouteData;
    var currentAction = rd.GetRequiredString("action");
    var currentController = rd.GetRequiredString("controller");

    return htmlHelper.BeginForm(currentAction, currentController, rd.Values, method);
}