Handle multiple button post

razor: <form action=”” method=”post”> <input type=”submit” value=”Save” name=”action:Save” /> <input type=”submit” value=”Send” name=”action:Send” /> </form> and controller: [HttpPost] [MultipleButton(Name = “action”, Argument = “Send”)] public ActionResult Send(MessageModel mm) { … } [HttpPost] [MultipleButton(Name = “action”, Argument = “Save”)] public ActionResult Save(MessageModel mm) { … }

Continue reading

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 reading

Content 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 reading

Difference 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 reading

Single 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 reading

Differences Between Hashtable and Dictionary

1. Hashtable is threadsafe and while Dictionary is not. 2. Dictionary is of Generic type whereas Hashtable is not of generic type. 2. Dictionary is types means that the values need not to boxing while Hashtable values  need to be boxed or unboxed because it stored the  values and keys as objects.      3. When…

Continue reading

What is mutable and immutable. Difference between string vs sting builder

When u change the value of Mutable objects the new memory is created and new value is stored in new memory.But in immutable the value is changed in same memory, this makes immutable objects to increase the performance.so in case if the string is frequently changed in the code at run time, it is advisable…

Continue reading