Saturday, 26 May 2018

Add a startup.cs class to your application


Startup page is mostly using to configuration for startup of the application when you are configuration OWIN or the OAuth authorization.

There are two what you can directly add it and  as a class file and decorate it as. OWinStartup:

  [assembly: OwinStartup(typeof(WebApiOAuth_1.App_Start.Startup))]


Or you can create startup.cs through the Visual Video by using the below process.
a.       Rt click on App_Start à Add à Class

XMLformatting in c#



Format the minify XML into readable way which help to view it properly and easy to read in C#. You can make your simple xml formatter by using the below few lines of code in C#.
static void Main(string[] args)
        {
            try
            {
                string xml = @"<?xml version='1.0' encoding='UTF - 8' ?><employees><employee><id>1</id><firstName>Leonardo</firstName>
            <lastName>DiCaprio</lastName><photo>https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgr5EO4zbh_Vl_1W3Pxwo9ty6C7GZuDhME8KIVAXi0-PmFL-jRxzLS_mHhWjSwZARP2Uzq-ci7TvJR_3YO056bYOf1PBV7zS2TeNv8gYyt54xH8toD7vZu0kMKSVIijC4QEZy5rB0I8ujA/s200/Leonardo+Dicaprio7.jpg</photo>
            </employee><employee><id>2</id><firstName>Johnny</firstName><lastName>Depp</lastName>
            <photo>http://4.bp.blogspot.com/_xR71w9-qx9E/SrAz--pu0MI/AAAAAAAAC38/2ZP28rVEFKc/s200/johnny-depp-pirates.jpg</photo>
            </employee><employee><id>3</id><firstName>Hritik</firstName><lastName>Roshan</lastName><photo>http://thewallmachine.com/files/1411921557.jpg</photo>
            </employee></employees> ";

Thursday, 24 May 2018

Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'


Could not load file or assembly 'Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 


Sunday, 20 May 2018

Binding DropDownList in MVC


In MVC we have 2 ways to bind the dropdown is strongly type and nomal way.
There are various ways that you can bind the dropdownlist in MVC.

1.       Binding Dropdownlist  using the view bag in MVC
Binding SelectedList to Dropdown

  List<SelectListItem> items = new List<SelectListItem>();
            items.Add(new SelectListItem() { Text = "Male", Value = "Male", Selected = false });
            items.Add(new SelectListItem() { Text = "Female", Value = "Female", Selected = true });

            SelectList selectList = new SelectList(items, "Value", "Text");


            ViewBag.Gender = selectList;

Binding it in HTML, like below
  @Html.DropDownList("Gender", ViewBag.Gender as SelectList)

Will get output as below.

Friday, 18 May 2018

Format date in ui-grid cellTemplate


This sample is using when you are implementing MVC with Angular 1.x and Angular Ui Grid.
Formatting of date field will be appearing like:



Sunday, 13 May 2018

Handling Exception in Global.asax in MVC



Instead of writing the try and catch throughout the application, global.asax , application_error method is the common place to handle all the error and based on the type of exception it will redirect to the page.



Tuesday, 8 May 2018

Selecting the active link in MVC



Based on selection or opening of the controller action the link will select in MVC like below.




There should you need to provide the css dynamically which is based on the action. You need to create the CSS style.
.activelink {
    color: #ffffff;
    background-color: #de0301;
    border-radius: 10px;
    margin-left: 4px;
}
If you see the below code there we are checking the (ViewContext.RouteData.Values["Controller"].ToString() == "Home"

Thursday, 19 April 2018

Provide security to Your WebApi using HttpMessageHandler


Using of HttpMessageHandler, help you to secure your WebApi action method, Even though it’s not the full proof security. But it is good to provide security based on tokens.

Step 1: Create A Web API project.
Follow below:

Step 2: Add a class file and giving the name as:

That You can give as any name





Wednesday, 14 February 2018

simple jquery popup example code


Simple jquery popup which generally use to show or to perform some operations as supplementary operations.

You will get the popup as like below.

This popup doesn’t need any plugin, you only need to take the reference of the

Saturday, 20 January 2018

cordova "no java files found that extend cordovaactivity"

Getting Error as:

Severity Code Description Project File Line Suppression State Error No Java files found which extend CordovaActivity. OilFreeRecipes 1

This issue is causing due to missing of MainActivity.Java File Generally it is residing on the below path.
[Application Name]\platforms\android\src\com
Here it should have the folder name based on the namespace you have given. Suppose I have given namespace as com.passion.oilfreerecipes So there should have folder passion --> OilfreeRecipes