What are the different action method’s return type?

1) ViewResult : Used to return a view to render html in the browser. this is the most common used action result

2)PartialViewResult: Similar to view result, it returns a partial view.

3) ContentResult: Used to return any type of content. By default it is used to return plain text but the actual content type can be explicitly defined

4) EmptyResult: this is equivalent to void method,it is by definition an action result object,but it does nothing.

5)FileResult:Used to return binary content.

6)HttpUnauthroizedResult: You can return an HttpUnauthrized result when the request tries to access restricted content that, for example its not available to anonymous user.

7)JavaScriptResult:Used to  return JavaScript code.

8)JsonResult: Used  to return any object in JavaScript Object Notation(JSON) format.

9)RedirectRresult:Used to perform an HTTP redirect to another URL.you can define it as temporary (code 302) or permanent (code 301)  HTTP redirect.

10)RedirectToRouteResult: used to perform an HTTP redirect ,but to specific route rather than a URL

 

 

The requested page cannot be accessed because the related configuration data for the page is invalid in MVC

The requested page cannot be accessed

The error message “The requested page cannot be accessed because the related configuration data for the page is invalid in MVC”  is occurred due to invalid code in the web.config file. Invalid code in the sense you may given a invalid tag like for <connectionString> you may given <constr>. it makes the error we should use the current xml tag names.

Please see the below examples

Actual tag code for connection string

<connectionString>

you may be made mistake like

<connectionstring>

See the above example the ‘S’ letter for the two example is different because the web.config file xml tags are case sensitive. it should follow the visual studio rules to avoid errors.

In web.config xml file we should specify the tags currently according to the visual studio needs.

if anything wrong in the web.config file you will get the error like

The requested page cannot be accessed because the related configuration data for the page is invalid in MVC

 

How to move second div to first in mobile view using css ?

we may need to show divs in different ways in mobile views. Like the same now consider a situation there is a requirement to move the second div to first and first div to second in mobile view. for web view it is normal.

You can find below code that helps to move second div to first and first div to second using css.

If you want to test

Step 1 : the code just copy the code
Step 2 : open a editor or notepad and paste the code
Step 3 : save the code in any location with file extension “.html” , Eg : index.html
Step 4 : open the file in a browser and check the mobile view.

Move second div to first and first div to second using css

<html>
<style>
.parent{
width:100%;
}

.parent div
{
width:50%;
float:left;

}
@media only screen and (max-width: 767px) {
   
    .parent 
    {   
       display: table;
    }
    .parent div{width: 100%;float: none}
    .leftColumn
    {
        display:table-footer-group; 
  color:red;
     
  
    }
    .rightColumn
    {
        display: table-header-group;
      
    } 
 
 }
</style>
<body>

<div class="parent">
 <div class="leftColumn">
 This is the first div
 </div>

 <div class="rightColumn">
 This is the second div
 </div>
<div>

</body>

</html>

 

 

How to use switch statement in c# ?

Switch statement is used to check a variable with a set of conditions called cases. We can check a variable whether the value satisfies certain conditions.
For example below I have checked a variable is A, B or C. in some case we need to do some operations according to the check then we can go for the switch case.

Syntax for switch statement in c#

switch(expression_data) {
case condition1 :
Method1(s);
break; /* optional */
case condition2 :
Method2(s);
break; /* optional */
.
.
.
.
.

default : /* Default is optional */
methodN(s);
}

Example for switch statement in c#

using System;
namespace FindVariable
{
class Program
{
static void Main(string[] args)
{
char character_variable = 'B';

switch (character_variable)
{
case 'A':
Console.WriteLine("Variable has value A");
break;
case 'B':
Console.WriteLine("Variable has value B");
break;
case 'C':
Console.WriteLine("Variable has value C");
break;

default:
Console.WriteLine("The variable not have the chartectors A,B and C");
break;
}
Console.WriteLine("The variable has value{0}", character_variable);
Console.ReadLine();
}
}
}

Output

Variable has value B
The variable has value B

Array in Javascript

Array is a variable that is used to hold more than one value in a single variable. That is we can hold a list of data inside an array.

How to declare an array in javascript ?

We can declare an array in two ways. these are the ways we can achieve it.

Example

var arrayName1 = new Array("data 1", "data 2", "data 3");
var arrayName2 = ["data 1", "data 1", "data 3"];

How to add elements to array in javascript ?

Javascript array has a method push, the method we can use to add new elements to the array. when we use push the element will be added at the end of the array.
Example

var arrayName1 = new Array("data 1", "data 2", "data 3");
var arrayLength=arrayName1.length; // output will be 3
arrayName1.push("data 4");
var arrayNewLength=arrayName1.length; // output will be 4

How to delete an elements from array in javascript?

Javascript array has method named pop , it help us to delete an element from an array. when we use pop the elements at the end will be deleted.

Example

var arrayName1 = new Array("data 1", "data 2", "data 3");
var arrayLength=arrayName1.length; // output will be 3
arrayName1.pop();
var arrayNewLength=arrayName1.length; // output will be 2

How to find number of elements in an array in javascript ?

Javascript array has a property called length , the length property help us to find the number of elements exist in an array.
Example

var arrayName1 = new Array("data 1", "data 2", "data 3");
var arrayLength=arrayName1.length; // output will be 3

What is comments and types of comments in javascript?

                          For two reasons we can have comments in the code, one is to define the description of the specific code and the another thing is to prevent the execution of code .

There are two type of comments are available in javascript

1. Single line comment
2. Multiple line comment

Single line comment

Single line comment is used to comment a single line of code.

Syntax

//the code we need to comment

Example

// var total=0;

Multiple line comment

Multiple line comment is used to comment a block of coded that is multy line commenting.

Syntax

/*
the code we need to comment line 1
the code we need to comment line 2
the code we need to comment line 3
*/

Example

/*
var a=10;
var b=20;
var c=a+b;
*/

 

How to comment codes in TWIG ?

Whenever we write codes we may need to comment some codes to avoid displaying and executing the line.we need two ways of commenting , they are single line commenting and multi line commenting.

Single line commenting

Single line commenting is used to comment a line of code .

Syntax

{# Commented code #}

Example

{#   <h3>{{ heading_title }}</h3>   #}

Multi line commenting

Multi line commenting is used to comment a part of codes or multiple lines of codes. the syntax and way of commenting is same as of single line commenting for the multi line commenting.

Syntax

{# Commented code #}

Example

{#

{% if product %}
<span>{{ product.title }}</span>
{% endif %}

#}

How to find Nth highest salary in Sql Server ?

How to find Nth highest salary in Sql Server ?

Finding the first or second or Nth highest salary of the person is a most important thing for the developers, as a developer we should know this. Mostly we hear this question in the interview.

Consider the below table with table name Employee

SELECT * FROM [dbo].[Employee]

How to find highest salary in Sql Server?

There are so many ways to find highest salary, you can see below some of the examples

Method 1

select max(salary) as highest_salary from [dbo].[Employee]

Method 2

select top 1 salary as highest_salary from [dbo].[Employee] order by salary desc

Method 3

;WITH CTE AS
(
SELECT salary ,ROW_NUMBER() OVER (ORDER BY Salary Desc) AS [Rank]
FROM [dbo].[Employee] group by salary
)
SELECT  salary as highest_salary
FROM CTE
WHERE [Rank]=1;

How to 2nd highest salary in Sql Server?

We are seen some of the methods to find highest salary above, we cannot use method 1 and method 2 to find the 2nd highest salary, but we can use the method 1 by little change in the code.

There are so many ways to 2nd highest salary, you can see below some of the example

Method 1

SELECT MAX(salary) FROM Employee WHERE Salary NOT IN ( SELECT Max(Salary) FROM Employee);

Method 2

SELECT TOP 1 Salary FROM ( SELECT TOP 2 Salary FROM Employee ORDER BY Salary DESC) AS MyTable ORDER BY Salary ASC;

Method 3

;WITH CTE AS
(
SELECT salary ,ROW_NUMBER() OVER (ORDER BY Salary Desc) AS [Rank]
FROM [dbo].[Employee] group by salary
)
SELECT  salary as highest_salary FROM CTE WHERE [Rank]=2;

How to Nth highest salary in Sql Server?

Previously we have seen highest salary and 2nd highest salary solutions, also we know the query using CTE is used again used in 2nd highest salary with a little modification, the modification is we are changing the rank

If we want 1st highest salary we have to give rank as 1

If we want 2nd highest salary we have to give rank as 2

So we can use the same query to find the nth salary like below

;WITH CTE AS
(
SELECT salary ,ROW_NUMBER() OVER (ORDER BY Salary Desc) AS [Rank]
FROM [dbo].[Employee] group by salary
)

SELECT  salary as highest_salary FROM CTE WHERE [Rank]=”Nth”;

Example

;WITH CTE AS
(
SELECT salary ,ROW_NUMBER() OVER (ORDER BY Salary Desc) AS [Rank] 
FROM [dbo].[Employee] group by salary
)
SELECT  salary as highest_salary FROM CTE WHERE [Rank]=”Nth”;

Finding 5th highest salary in sql server

;WITH CTE AS
(
SELECT salary ,ROW_NUMBER() OVER (ORDER BY Salary Desc) AS [Rank]
FROM [dbo].[Employee] group by salary
)
SELECT  salary as highest_salary
FROM CTE WHERE [Rank]=5;

What are the main differences between DML vs DDL?

The main difference between DML vs DDL is – one for managing data in database and other for define database. DML stands for Data Manipulation Language and DDL stands for Data Definition Language.

    1. DML statements are used to manage the data in a database just like insert, update, delete etc.
      insert into table(col1, col2, col3) value(val1, val2, val3)
    2. DDL statements are used to create and define database structure just like create, alter, drop etc.
      create table tablename (col1 datatype, col2 datatype, col3 datatype)
    3. DML statements work with rows of data in table. For example, insert will create one or more rows in a table, where DDL works on database objects like table or views etc. For example, create will create a new object of table or view or procedure etc.
    4. Most of the DML support where clause and having clause for filtering data and order by and group by functions. But DDL does not support these functions.
    5. Transactions can be applied to DML statements. Which means, COMMIT and ROLLBACK are supported in DML statements. But DDL does not support Transactions. Which means once a table is created it cannot be roll backed. It need another DDL statement of DROP to remove the table from database.
    6. DDL statements cannot fire any triggers. But DML can fire triggers.