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

Read Array object in Javascript Based on Query String

Please check the previous article  Click here to see how we can read the value which we pass in query string
Now Framing the javascript array  Object,


var val = [
        { Id: 1, Image: 'Content/Images/2.jpg', Value:'This is 1 content' },
        { Id: 2, Image: 'Content/Images/2.jpg', Value:'This is 2 content' }
    ];

Code to read array of object is javascript

Saturday, 23 December 2017

Reading Query string Values in Javascript

Using simple javascript to get the  query string value of URL.


We have URL as 
<a href="DisplayContent.html?id=0"> 0</a>
<a href="DisplayContent.html?id=1">1</a>

To Read the content of URL you can use below method as;


function getParameterValueByName(name, url) {
        if (!url) url = window.location.href;
        name = name.replace(/[\[\]]/g, "\\$&");
        var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
            results = regex.exec(url);
        if (!results) return null;
        if (!results[2]) return '';
        return decodeURIComponent(results[2].replace(/\+/g, " "));
    }

Friday, 8 December 2017

The specified type member '' is not supported in LINQ to Entities.

Getting issue with entity framework for newly added column into database table.

The specified type member '' is not supported in LINQ to Entities. Only initializers, entity members, and entity navigation properties are supported.