MVC Action Names & NonAction method


            In MVC URLs not being case sensitive. So that for example if you have the request “Home/About” this goes to HomeController and About action, as well as hOmE/AbOUT is going to the same controller and same action method. 
            SUPPOSE  if we have 2 about action methods in the same controller with different cases such as:


public class HomeController:Controller{
    public ViewResult About()    {
        return View();
   }
    public ViewResult aBOut()
    {
        return View();
    }
}
when Icall action method About using following url http://your applicationname/Index/ABOUT I got following server page error

The framework can’t determine which ‘about’ function to call, and throws the exception telling that the call is ambiguous. Of course one way to fix this problem is to change the action name. If for some reason you don’t want to change the action name, and one of these function is not an action, then you can decorate this non action method with NonAction attribute. Example:

[NonAction]
public ActionResult aBOut()
{
   return View();
}


JSON serialization error [maxJsonLength property.]

In my previous project I need to retrieve ticket  from Web service.When I request the web service it return a ticket as JSON format.Some time I need to retrieve more than 10 lacks ticket per requet.In that time I got the following error

Exception information:
Exception type: InvalidOperationException
Exception message: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
Solution is 
            We need to set Maximum allowed length of json response in Web.config file 
The MaxJsonLength property cannot be unlimited, is an integer property that defaults to 102400 (100k).

HOW TO CHECK YOUR LAST SQL DATABASE BACKUP TIME


      It is good to check when was your last backup happened, I have wrote small query which it pull the information from msdb backupset table, it lists all the database names with last backup date and time.
It is very easy to track when was your last backup was happened. You can use the following query
.

Create a Foreign Key relationship using Code First Entity Framework In asp.net MVC4

In this post I will explain How to create Foreign Key relationship in  Entity Framework(EF).

When you create a model of relation database some time we got following error
Unable to retrieve association information for association 'Models.Product_Parent'. Only models that include foreign key information are supported. See Entity Framework documentation for details on creating models that include foreign key information.

         I will explain how to create Model class for following  relation data base

Login failed for user "sa" error 18456


In SQL Server's most common issue in securities is login failed for user, Error 18456.
To resolve 18456 error, you have to change the Server Authentication mode "SQL Server and Windows Authentication mode".
In order to resolve the above issue through selecting "SQL Server and Windows Authentication mode", please refer to the following steps:
Here is the error #18456 getting while connecting to the server through "SA" login and password.

MVC Action link with Html text

In this post I will explain how to write MVC Action link with Html text.

MVC Razor View

<a href='@Url.Action("MyAction", "MyController")'>
     <span>My Asp.Net</span>
</a>


MVC Html View


<a href='<%: Url.Action("MyAction", "MyController") %>'>
     <span>My Asp.Net</span>
</a>



String Format for DateTime [C#]

This example shows how to format Date Time using String.Format method. All formatting can be done also using DateTime.ToString method.
Custom Date Time Formatting
There are following custom format specifiers y (year), M (month), d (day), h (hour 12), H (hour 24), m (minute), s (second), f (second fraction), F (second fraction, trailing zeroes are trimmed),t (P.M or A.M) and z (time zone).
Following examples demonstrate how the format specifiers are rewritten to the output.
// create date time 2008-03-09 16:05:07.123
DateTime dt = new DateTime(2008, 3, 9, 16, 5, 7, 123);

String.Format("{0:y yy yyy yyyy}", dt);  // "8 08 008 2008"   year
String.Format("{0:M MM MMM MMMM}", dt);  // "3 03 Mar March"  month
String.Format("{0:d dd ddd dddd}", dt);  // "9 09 Sun Sunday" day
String.Format("{0:h hh H HH}",     dt);  // "4 04 16 16"      hour 12/24
String.Format("{0:m mm}",          dt);  // "5 05"            minute
String.Format("{0:s ss}",          dt);  // "7 07"            second
String.Format("{0:f ff fff ffff}", dt);  // "1 12 123 1230"   sec.fraction
String.Format("{0:F FF FFF FFFF}", dt);  // "1 12 123 123"    without zeroes
String.Format("{0:t tt}",          dt);  // "P PM"            A.M. or P.M.
String.Format("{0:z zz zzz}",      dt);  // "-6 -06 -06:00"   time zone

         

Reverse of a string without using the Reverse function in C# and VB

This is a simple code snippet for reversing a string without using the Reverse function. For example, we have a string "He is playing in a ground." without using a function, we can reverse it using the code snippet below. Code is given in both C# and VBalso. This will be helpful to beginners. If you have any queries, please feel free to ask me.
example

Tamil keyboard

The Html code is


<div dir="ltr" style="text-align: left;" trbidi="on">
<center>

<input id="Phrase" size="80" style="font-size: 16;" type="text" value="" />

<script language="JavaScript" type="text/javascript">

 function AppendCharacter(ChrToAppend)
 {
   document.getElementById("Phrase").value += ChrToAppend;
 }



 </script>

<table><tbody>
<tr>             <td>
<input name="02947" onclick="AppendCharacter('ஃ');" style="font-size: 18;" type="button" value=" ஃ " />
</td>             <td>
<input name="02949" onclick="AppendCharacter('அ');" style="font-size: 18;" type="button" value=" அ " />
</td>             <td>
<input name="02950" onclick="AppendCharacter('ஆ');" style="font-size: 18;" type="button" value=" ஆ " />
</td>             <td>
<input name="02951" onclick="AppendCharacter('இ');" style="font-size: 18;" type="button" value=" இ " />
</td>             <td>
<input name="02952" onclick="AppendCharacter('ஈ');" style="font-size: 18;" type="button" value=" ஈ " />
</td>             <td>
<input name="02953" onclick="AppendCharacter('உ');" style="font-size: 18;" type="button" value=" உ " />
</td>             <td>
<input name="02954" onclick="AppendCharacter('ஊ');" style="font-size: 18;" type="button" value=" ஊ " />
</td>             <td>
<input name="02958" onclick="AppendCharacter('எ');" style="font-size: 18;" type="button" value=" எ " />
</td>             <td>
<input name="02959" onclick="AppendCharacter('ஏ');" style="font-size: 18;" type="button" value=" ஏ " />
</td>             <td>
<input name="02960" onclick="AppendCharacter('ஐ');" style="font-size: 18;" type="button" value=" ஐ " />
</td>             <td>
<input name="02962" onclick="AppendCharacter('ஒ');" style="font-size: 18;" type="button" value=" ஒ " />
</td>         </tr>
</tbody></table>
<table><tbody>
<tr>             <td>
<input name="02963" onclick="AppendCharacter('ஓ');" style="font-size: 18;" type="button" value=" ஓ " />
</td>             <td>
<input name="02964" onclick="AppendCharacter('ஔ');" style="font-size: 18;" type="button" value=" ஔ " />
</td>             <td>
<input name="02965" onclick="AppendCharacter('க');" style="font-size: 18;" type="button" value=" க " />
</td>             <td>
<input name="02969" onclick="AppendCharacter('ங');" style="font-size: 18;" type="button" value=" ங " />
</td>             <td>
<input name="02970" onclick="AppendCharacter('ச');" style="font-size: 18;" type="button" value=" ச " />
</td>             <td>
<input name="02972" onclick="AppendCharacter('ஜ');" style="font-size: 18;" type="button" value=" ஜ " />
</td>             <td>
<input name="02974" onclick="AppendCharacter('ஞ');" style="font-size: 18;" type="button" value=" ஞ " />
</td>             <td>
<input name="02975" onclick="AppendCharacter('ட');" style="font-size: 18;" type="button" value=" ட " />
</td>             <td>
<input name="02979" onclick="AppendCharacter('ண');" style="font-size: 18;" type="button" value=" ண " />
</td>             <td>
<input name="02980" onclick="AppendCharacter('த');" style="font-size: 18;" type="button" value=" த " />
</td>             <td>
<input name="02984" onclick="AppendCharacter('ந');" style="font-size: 18;" type="button" value=" ந " />
</td>             <td>
<input name="02985" onclick="AppendCharacter('ன');" style="font-size: 18;" type="button" value=" ன " />
</td>         </tr>
</tbody></table>
<table><tbody>
<tr>             <td>
<input name="02986" onclick="AppendCharacter('ப');" style="font-size: 18;" type="button" value=" ப " />
</td>             <td>
<input name="02990" onclick="AppendCharacter('ம');" style="font-size: 18;" type="button" value=" ம " />
</td>             <td>
<input name="02991" onclick="AppendCharacter('ய');" style="font-size: 18;" type="button" value=" ய " />
</td>             <td>
<input name="02992" onclick="AppendCharacter('ர');" style="font-size: 18;" type="button" value=" ர " />
</td>             <td>
<input name="02993" onclick="AppendCharacter('ற');" style="font-size: 18;" type="button" value=" ற " />
</td>             <td>
<input name="02994" onclick="AppendCharacter('ல');" style="font-size: 18;" type="button" value=" ல " />
</td>             <td>
<input name="02995" onclick="AppendCharacter('ள');" style="font-size: 18;" type="button" value=" ள " />
</td>             <td>
<input name="02996" onclick="AppendCharacter('ழ');" style="font-size: 18;" type="button" value=" ழ " />
</td>             <td>
<input name="02997" onclick="AppendCharacter('வ');" style="font-size: 18;" type="button" value=" வ " />
</td>             <td>
<input name="02999" onclick="AppendCharacter('ஷ');" style="font-size: 18;" type="button" value=" ஷ " />
</td>             <td>
<input name="03000" onclick="AppendCharacter('ஸ');" style="font-size: 18;" type="button" value=" ஸ " />
</td>             <td>
<input name="03001" onclick="AppendCharacter('ஹ');" style="font-size: 18;" type="button" value=" ஹ " />
</td>         </tr>
</tbody></table>
<table><tbody>
<tr>             <td>
<input name="03006" onclick="AppendCharacter('ா');" style="font-size: 18;" type="button" value=" ா " />
</td>             <td>
<input name="03007" onclick="AppendCharacter('ி');" style="font-size: 18;" type="button" value=" ி " />
</td>             <td>
<input name="03008" onclick="AppendCharacter('ீ');" style="font-size: 18;" type="button" value=" ீ " />
</td>             <td>
<input name="03009" onclick="AppendCharacter('ு');" style="font-size: 18;" type="button" value=" ு " />
</td>             <td>
<input name="03010" onclick="AppendCharacter('ூ');" style="font-size: 18;" type="button" value=" ூ " />
</td>             <td>
<input name="03014" onclick="AppendCharacter('ெ');" style="font-size: 18;" type="button" value=" ெ " />
</td>             <td>
<input name="03015" onclick="AppendCharacter('ே');" style="font-size: 18;" type="button" value=" ே " />
</td>             <td>
<input name="03016" onclick="AppendCharacter('ை');" style="font-size: 18;" type="button" value=" ை " />
</td>             <td>
<input name="03018" onclick="AppendCharacter('ொ');" style="font-size: 18;" type="button" value=" ொ " />
</td>             <td>
<input name="03019" onclick="AppendCharacter('ோ');" style="font-size: 18;" type="button" value=" ோ " />
</td>             <td>
<input name="03020" onclick="AppendCharacter('ௌ');" style="font-size: 18;" type="button" value=" ௌ " />
</td>             <td>
<input name="03021" onclick="AppendCharacter('்');" style="font-size: 18;" type="button" value=" ் " />
</td>         </tr>
</tbody></table>
<table><tbody>
<tr>             <td>
<input name="space" onclick="AppendCharacter(' ');" type="button" value="                     " />
</td>         </tr>
</tbody></table>
</center>

<hr />
</div>

The Out put is

The Html code is

The Out put is

Arrays resized dynamically



In C#, arrays cannot be resized dynamically. One approach is to use System.Collections.ArrayList instead of a native array. Another (faster) solution is to re-allocate the array with a different size and to copy the contents of the old array to the new array. The generic function resizeArray (below) can be used to do that.
Example is bellow