Monday, 1 June 2015

difference between viewbag and viewdata and tempdata in mvc3

the main difference below,
ViewData:
  • ViewData is a dictionary of objects that is derived from ViewDataDictionary class and accessible using strings as keys
  • It’s required type casting for complex data type and check for null values to avoid error.

ViewBag: 
  • ViewBag doesn’t require typecasting for complex data type.
  • ViewBag is a dynamic property that takes advantage of the new dynamic features in C# 4.0. 

Check the following example:
public class HomeController : Controller
{
    public ActionResult Index()
    {
        var emp = new Employee
        {
            EmpID=101,
            Name = "Deepak",
            Salary = 35000,
            Address = "Delhi"
        };

        ViewData["emp"] = emp;
        ViewBag.Employee = emp;

        return View(); 
    }
}
And the code for View is as follows:
@model MyProject.Models.EmpModel;
@{ 
 Layout = "~/Views/Shared/_Layout.cshtml"; 
 ViewBag.Title = "Welcome to Home Page";
 var viewDataEmployee = ViewData["emp"] as Employee; //need type casting
}
<h2>Welcome to Home Page</h2>
This Year Best Employee is!
<h4>@ViewBag.emp.Name</h4>
<h3>@ViewData.Employee.Name</h3>

Wednesday, 27 May 2015

javascript == and === difference

1. === operater
=== means value must be equal and type as well
Ex:
var value1=1;
var value2='1';

if(value1===value2) /// this will return false because this value type is different(javascript will do internal type casting even though if we use === it will follow the strict rules),

and

if(0===false) // this will return false because different data type


2.== operator

== means value must be equal,

Ex:
var value1=1;
var value2='1';
if(value1==value2) /// this will return true because (==) will check only value(javascript handle type conversion).

and
if(0==false) // this will return true because false is equal to 0

Monday, 11 May 2015

Best 100+ Frequently Asked Interview Questions in .Net SQL

refer this link

http://www.webblogsforyou.com/100-frequently-asked-interview-questions-on-asp-net-sql-server-oop-concepts/

Thursday, 30 April 2015

cannot open backup device operating system error 5(access is denied.)

possible reason for this errors are,

1. there is no directory with the name
ex, if u r mention path as 'D:\test\abc.bak' may be this directory wont be there or not access for your credentials.
2.second possible is, u wont be having enough space in the disk to save the data.
3.you may not having enough permission/rights in logs drive
ex, if your mention a folder name, for that folder u might not having write permission, something like that.

how to take database backup using sql query

in query window use this syntex:

backup datsbase databasename to disk='location to store'


Example:

backup database sureshdatabase in disk = 'D:\sureshDBBackup\sureshdatabase.bak'

after forming this query execute.




Friday, 17 April 2015

assign null value to enum in c#

You can use the "?" operator for a enum nullable type.

Ex:
public enumname? objenum = null;

or else u can create one more enum as none then use it.