razor: 1 2 3 4 5 <code><form action="" method="post"> <strong> <input type="submit" value="Save" name="action:Save" /> <input type="submit" value="Send" name="action:Send" /></strong> </form> </code> <code><form action=”” method=”post”> <strong> <input type=”submit” value=”Save” name=”action:Save” /> <input type=”submit” value=”Send” name=”action:Send” /></strong> </form> </code> and controller: 1 2 3 4 5 6 7 8 <code> [HttpPost] <strong>[MultipleButton(Name =…
Continue readingInterview Question
Handle the unhandled exception in Window Service C#
Sometimes window service crash due to unhandled exception occur in the code. Which cause service to be on halt without any error log and we are unable to restart or stop the service in the windows. In .net framework 4.5, Microsoft provides a method to handle the exception in the async event handler. Simply write…
Continue readingASP.NET Web API 2 action method return types
A Web API 2 action method return types can be any of the following : Void HttpResponseMessage IHttpActionResult Other type or Complex type Void When an ASP.NET Web API return type is void, it will return an empty HTTP response. In the following example a web API with void return: Example 1 2 3…
Continue readingContent negotiation in WebAPI or other rest service.

The Accept header is used by HTTP clients to tell the server what content types they’ll accept. The server will then send back a response, which will include a Content-Type header telling the client what the content type of the returned content actually is. However, as you may have noticed, HTTP requests can also contain Content-Type headers. Why? Well, think about POST or PUT requests….
Continue readingDifference between Covariance & Contravariance
It’s probably easiest to give examples – that’s certainly how I remember them. (covariant return types/contravariant parameter types) Covariance Canonical examples: IEnumerable<out T>, Func<out T> You can convert from IEnumerable<string> to IEnumerable<object>, or Func<string> to Func<object>. Values only come out from these objects. It works because if you’re only taking values out of the API, and it’s going to return something specific (like string), you can…
Continue readingEntity Framework Code First: Get Entities From Local Cache or the Database
Entity Framework Code First makes it very easy to access local (first level) cache: you just access the DbSet<T>.Local property. This way, no query is sent to the database, only performed in already loaded entities. If you want to first search local cache, then the database, if no entries are found, you can use this…
Continue readingDifference between Encapsulation and Abstraction in OOPS
Abstraction and Encapsulation are two important Object Oriented Programming (OOPS) concepts. Encapsulation and Abstraction both are interrelated terms. Real Life Difference Between Encapsulation and Abstraction Encapsulate means to hide. Encapsulation is also called data hiding.You can think Encapsulation like a capsule (medicine tablet) which hides medicine inside it. Encapsulation is wrapping, just hiding properties and methods. Encapsulation…
Continue readingContent negotiation in Web API(accept and content-type attribute of header)
Content negotiation is a way to serve client-specific representations of the same resource. A client might send this HTTP request: GET http://localhost.:21069/api/products/1 HTTP/1.1 Host: localhost.:21069 <strong>Accept</strong>: application/json, text/javascript, */*; q=0.01 In response, the server might send: HTTP/1.1 200 OK <strong>Content-Type:</strong> application/json; charset=utf-8 Content-Length: 57 Connection: Close The Accept header is used by HTTP clients to…
Continue readingSingle vs SingleOrDefault vs First vs FirstOrDefault
When to use Single, SingleOrDefault, First and FirstOrDefault You should take care of following points while choosing Single, SingleOrDefault, First and FirstOrDefault: When you want an exception to be thrown if the result set contains many records, use Single or SingleOrDefault. When you want a default value is returned if the result set contains no…
Continue readingStack vs. Heap
Here are our two golden rules: A Reference Type always goes on the Heap; easy enough, right? Value type always goes on the Stack. Value Types: In C#, all the “things” declared with the following list of type declarations are Value types (because they are from System.ValueType): bool byte char decimal double enum float…
Continue reading