- Install "dotless" using Package Manager Console ("install-package dotless") or the Nuget Package Manager
- Open Web.config, locate the "dotless" section, and change it as the following.
The main thing is to add<validation validateIntegratedModeConfiguration="false"/>
to the <system.webServer> node.
<dotless minifyCss="false" cache="true" web="false" /> <system.webServer> <validation validateIntegratedModeConfiguration="false"/> <handlers> <add name="dotless" path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler,dotless.Core" resourceType="File" preCondition="" /> </handlers> </system.webServer> - If the main less file is "my.less", which imports all other less files, add the following comment at the top of each less file except the "my.less".
/// <reference path="my.less" />
Thursday, August 28, 2014
Using Less in Visual Studio 2013 Web Project
Here is a cheat sheet on "what to do" to start using LESS on Visual Studio 2013 web project.
Wednesday, August 20, 2014
Enable vertical split of the same CSHTML view file in Visual Studio 2013
In Visual Studio 2013, you can open the same C# file twice and view them vertically side-by-side by opening the C# file, selecting the menu [Window] --> [New Window] and then selecting [Window] --> [New Vertical Tab Group]. However, for *.cshtml MVC View files, this does not work. The [Window] --> [New Window] menu item is grayed out.
To enable [Window] --> [New Window] menu item for *.cshtml file, you can try this registry hack.
- Close Visual Studio 2013 if currently open.
- Use RegEdit and go to
[HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\12.0_Config\Languages\Language Services\HTMLX] . - Find "Single Code Window Only" entry.
- Change its value from 1 to 0.
- Start Visual Studio.
Now you should be able to open a *.cshtml file, select [New Window] from the [Window] menu to open another editor window of the same *.cshtml file, right-click on the the new editor window's tab and select [New Vertical Tab Group] to create side-by-side editor view of the same file. Changes you make on one editor window will instantly appear on the other editor window of the same file.
onclick event handler - get reference to the clicked element
There are a couple of ways to get the reference to the clicked element, which has onclick event on itself.
Method 1
Method 2
Method 1
<input type="button" id="btn1" value="Remove" onclick="removeSelf(event)" />
<script type="text/javascript">
function removeSelf(e){
var target = (e.target) ? e.target : e.srcElement // IE uses srcElement
target.style.display = 'none';
target.parentNode.removeChild( target ); // to remove the element
$(target).remove(); // to remove the element using jQuery
}
</script>
In Method 1, event is used as parameter. An Event object is created automatically whenever an event is fired, i.e., via user action, key press, mouse movement, etc. To find the source where the event occurred, the property name is either target or srcElement (in IE).
Method 2
<input type="button" id="btn1" value="Remove" onclick="removeSelf(this)" />
<script type="text/javascript">
function removeSelf(object){
object.style.display = 'none';
target.parentNode.removeChild( target ); // to remove the element
$(target).remove(); // to remove the element using jQuery
}
</script>
Monday, July 7, 2014
MVC Ad-hoc DropDownList for PageSize
Example of Razor DropDown List for PageSize in an Index View using ViewBag.
Here is a controller
Here is a controller
public class ProductController : Controller
{
public ActionResult Index( int? page, int? pagesize )
{
...
int pageSize = pagesize ?? 5;
List<SelectListItem> items = new List<SelectListItem>{
new SelectListItem{ Text="5", Value="5" },
new SelectListItem{ Text="10", Value="10" }
}
// items = List<SelectListItem>
// "Value" = ValueText
// "Text" = DisplayText
// pagesize = SelectedListItem's Value from querystring
ViewBag.PageSizeList = new SelectList( items, "Value", "Text", pagesize );
ViewBag.CurrentPageSize = pageSize
}
}
Here is the view
@using PagedList @using PagedList.Mvc @model IEnumerable<form id="form1" action=@Url.Action("Index", "Product") method="get"> ... @Html.DropDownList( "pagesize", (SelectList)ViewBag.PageSizeList ) // We keep DropDown list's name separate from ViewBag element's name @foreach ( var item in Model ) { } <table><tbody> <tr><td>...</td></tr> </tbody></table> @Html.PagedListPager( (IPagedList)Model, page => Url.Action( "Index", new { page, pagesize = @ViewBag.CurrentPageSize }) </form> <script type="text/javascript" src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"> </script> <script type="text/javascript"> $(function(){ // When onchange event occurs on <select id="pagesize">, // simply submit the form, which will submit the new pagesize value as querystring. $('#pagesize').on('change', function(){ $('#form1').submit(); }); }); </script>
Saturday, February 15, 2014
jQuery UI dialog jump issue workaround
When jQueryUI Dialog is used with "draggable = on", it would jump down by the scroll offset of parent page when the Dialog is being dragged via mouse. One of the nice workarounds to keep the draggable jQuery UI dialog in proper position without "jumping down" would be to set the dialog's parent position to 'fixed'. (By the way, this is the default behavior of Bootstrap's default modal window behavior, too.)
Below is a simple example to implement this workaround to a jQuery UI dialog. This works equally well for both modal and non-modal dialogs.
Hopefully, this workaround will provide better user experience on top of all the great features in jQuery UI library.
Below is a simple example to implement this workaround to a jQuery UI dialog. This works equally well for both modal and non-modal dialogs.
$(function(){
$('#dialog_1').dialog({
autoOpen: false,
create: function( event ){
// set dialog's parent position to 'fixed' under the create event
$( event.target ).parent().css( 'position', 'fixed' );
}
});
$('#btn_1').click(function(){
// to reposition the dialog to the center when re-opened
$('#dialog_1').dialog( 'option', 'position', 'center' );
$('#dialog_1').dialog( 'open' );
});
});
Hopefully, this workaround will provide better user experience on top of all the great features in jQuery UI library.
Tuesday, February 11, 2014
Get disk space info of all drives
The following SQL Server stored procedure could be useful when you need to get all disk space info quickly.
ALTER procedure [dbo].[usp_get_disk_space_info]
( @freeDiskSpace varchar(4000) output, @totalDiskSpace varchar(4000) output )
as
begin
exec ( 'sp_configure ''xp_cmdshell'', 1' )
exec ( 'reconfigure')
declare @psinfo table ( data nvarchar(1000) )
declare @t table(Drive varchar(2), FreeSpaceGB decimal(17,1), SizeGB decimal(17,1))
insert into @psinfo
EXEC xp_cmdshell 'Powershell.exe "Get-WMIObject Win32_LogicalDisk -filter "DriveType=3"| Format-Table DeviceID, FreeSpace, Size"'
delete from @psinfo where data is null or data like '%DeviceID%' or data like '%---%'
update @psinfo set data = REPLACE(data, ' ', ',');
;With DriveSpace as (
select SUBSTRING(data,1,2) as [Drive],
replace((left((substring(data,(patindex('%[0-9]%',data)) , len(data))),CHARINDEX(',', (substring(data,(patindex('%[0-9]%',data)) , len(data))))-1)),',','')
as [FreeSpace] ,
replace(right((substring(data,(patindex('%[0-9]%',data)) , len(data))),PATINDEX('%,%', (substring(data,(patindex('%[0-9]%',data)) , len(data))))) ,',','')
as [Size]
from @psinfo
)
insert into @t
SELECT Drive,
convert(dec( 6,2),CONVERT(dec(17,1),FreeSpace)/(1024*1024*1024)) as FreeSpaceGB,
convert(dec( 6,2),CONVERT(dec(17,1), size)/(1024*1024*1024)) as SizeGB
FROM DriveSpace;
declare @FreeSpaceGB varchar(1000)
declare @SizeGB varchar(1000)
set @FreeSpaceGB = stuff((select ', ' + Drive + ' ' + cast(FreeSpaceGB as varchar) + 'GB' from @t for XML PATH('') ), 1, 2, '')
set @SizeGB = stuff((select ', ' + Drive + ' ' + cast(SizeGB as varchar) + 'GB' from @t for XML PATH('') ), 1, 2, '')
select @freeDiskSpace = @FreeSpaceGB
select @totalDiskSpace = @SizeGB
exec ( 'sp_configure ''xp_cmdshell'', 0' )
exec ( 'reconfigure')
end
Thursday, December 19, 2013
How to flush DNS cache in Mac
The Mac equivalent of ipconfig /flushdns in Windows is as follows.
In Mavericks (OSX 10.9):
dscacheutil -flushcache; sudo killall -HUP mDNSResponder
In Lion (OSX 10.7) and Mountain Lion (OSX 10.8):
sudo killall -HUP mDNSResponder
In OSX 10.5 and 10.6
dscacheutil -flushcache
In Mavericks (OSX 10.9):
dscacheutil -flushcache; sudo killall -HUP mDNSResponder
In Lion (OSX 10.7) and Mountain Lion (OSX 10.8):
sudo killall -HUP mDNSResponder
In OSX 10.5 and 10.6
dscacheutil -flushcache
Subscribe to:
Posts (Atom)