Friday 30 December 2011

ASP.NET MVC : Using C# keyword 'class' as HTML attribute

If you are developing an ASP.NET MVC application you will have to set the CSS class name of an HTML element or INPUT control using HTML Helper methods. For example


@Html.RadioButton("status", "1", true, new { id = "status", class='radio' })


tries to set the CSS class name of the radio button to 'radio'. C# will not allow to do this as "class" is a C# keyword. You have to prefix "class" with an @ to fix this.


@Html.RadioButton("status", "1", true, new { id = "status", @class='radio' })


will work.

Problem setting an html attribute containing hyphens in ASP.NET MVC

C# doen't allow you to have a hyphen in the name of a property. For example if you try something like


@Html.TextBox("firstname", "", new { id = "firstname", maxlength = 100, data-val="true", data-val-required="Please enter the first name of the contact." })


It will fail to run.

Try using underscores which should be automatically converted into dashes by the standard HTML helpers:


@Html.TextBox("firstname", "", new { id = "firstname", maxlength = 100, data_val="true", data_val_required="Please enter the first name of the contact." })

Thursday 29 December 2011

Ipconfig syntax

Ipconfig

Displays all current TCP/IP network configuration values and refreshes Dynamic Host Configuration Protocol (DHCP) and Domain Name System (DNS) settings. When used without parameters, ipconfig displays the IP address, subnet mask, and default gateway for all adapters.

Syntax

ipconfig [/all] [/renew [Adapter]] [/release [Adapter]] [/flushdns] [/displaydns] [/registerdns] [/showclassid Adapter] [/setclassid Adapter [ClassID]]

Parameters

/all : Displays the full TCP/IP configuration for all adapters. Without this parameter, ipconfig displays only the IP address, subnet mask, and default gateway values for each adapter. Adapters can represent physical interfaces, such as installed network adapters, or logical interfaces, such as dial-up connections.

/flushdns : Flushes and resets the contents of the DNS client resolver cache. During DNS troubleshooting, you can use this procedure to discard negative cache entries from the cache, as well as any other entries that have been added dynamically.

/displaydns : Displays the contents of the DNS client resolver cache, which includes both entries preloaded from the local Hosts file and any recently obtained resource records for name queries resolved by the computer. The DNS Client service uses this information to resolve frequently queried names quickly, before querying its configured DNS servers.

/registerdns : Initiates manual dynamic registration for the DNS names and IP addresses that are configured at a computer. You can use this parameter to troubleshoot a failed DNS name registration or resolve a dynamic update problem between a client and the DNS server without rebooting the client computer. The DNS settings in the advanced properties of the TCP/IP protocol determine which names are registered in DNS.

/?: Displays help at the command prompt.

Examples



To display the basic TCP/IP configuration for all adapters, type:

ipconfig

To display the full TCP/IP configuration for all adapters, type:

ipconfig /all

To renew a DHCP-assigned IP address configuration for only the Local Area Connection adapter, type:

ipconfig /renew "Local Area Connection"

To flush the DNS resolver cache when troubleshooting DNS name resolution problems, type:

ipconfig /flushdns

How to flush DNS cache in Windows?

To flush DNS cache in Microsoft Windows (Windows 7, Windows XP, Windows ME, Win 2000):-

- Start -> Run -> type cmd

- in command prompt, type ipconfig /flushdns

- Done! Your Windows DNS cache has just been flushed.

Friday 23 December 2011

The C# ?? null coalescing operator

The C# ?? operator provides a nice way to check whether a value is null, and if so return an alternate value.

Simply put, the ?? operator checks whether the value provided on the left side of the expression is null, and if so it returns an alternate value indicated by the right side of the expression. If the value provided on the left side of the expression isn't null, then it returns the original value.

string message = "Welcome";
string result = message ?? "Good Bye";
//outcome: result == "Welcome"

string message = null;
string result = message ?? "Good Bye";
//outcome: result == "Good Bye"

int? age = 21;
int result = age ?? 0;
//outcome: result == 21


int? age = null;
int result = age ?? 0;
//outcome: result == 0

Click here to read more.