Button type “button” vs. “submit”

The type of the button. Possible values are:

  • submit: The button submits the form data to the server. This is the default if the attribute is not specified, or if the attribute is dynamically changed to an empty or invalid value.
  • reset: The button resets all the controls to their initial values.
  • button: The button has no default behavior. It can have client-side scripts associated with the element’s events, which are triggered when the events occur.







debug web service project in same solution as web site project

In your solution file, click properties go to the Startup project node (if it is not already selected)

Next select Multiple startup projects. Select your website and your webservice and in the Action column make sure both of them have “Start” selected.

Now when you debug your website and put a break point in you webservice it should hit the break point.

Thats all i can think of for your problem. Hope it helps.




How to initialize IEnumerable that be empty and allow to Concat to it?

It seams all you want to do is filter your context.Books by some criteria.

IEnumerable<Book> books = context.Books.Where(b => someConditions);

If you still need the empty IEnumerable you can just call Enumerable.Empty():

IEnumerable<Book> books = Enumerable.Empty<Book>();





Web API error: The ‘ObjectContent`1’ type failed to serialize the response body for content type ‘application/xml

Add following liners in dbcontext constructor

public DbContext() // dbcontext constructor
            : base("name=ConnectionStringNameFromWebConfig")
     this.Configuration.LazyLoadingEnabled = false;
     this.Configuration.ProxyCreationEnabled = false;

Another change has to do for App_Start / WebApiConfig.cs class in my MVC Web API project

var json = config.Formatters.JsonFormatter;
json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;



jquery detect textbox value change NOT based on user input



var $myText = $(“#myText”); $myText.data(“value”, $myText.val()); setInterval(function() { var data = $myText.data(“value”), val = $myText.val(); if (data !== val) { $myText.data(“value”, val); alert(“changed”); } }, 100);


An existing connection was forcibly closed by the remote host

I got below error when I try to fetch information from database using WCF service. I was using model entities directly because of this my code not able to fetch data. So I used following technic and it worked well. Basically we need to use DTOs to do data serialization.

use DTOs (Data Transfer Objects), this is an example of how Newspaper class could be:

public class NewspaperDTO
    public NewspaperDTO(Newspaper newspaper)
        this.Name = newspaper.Name;
        this.Image = newspaper.Image;
        this.Link = newspaper.Link;
        this.Encoding = newspaper.Encoding;

    public string Name { get; set; }

    public string Image { get; set; }

    public string Link { get; set; }

    public string Encoding { get; set; }

And then in your service:

public List<NewspaperDTO> GetNews()
    return entities.Newspapers.Select(a => new NewspaperDTO(a)).ToList();



MVC Project from github

Source: https://github.com/thomasgalliker/EmployeeManagement

## EmployeeManagement Demo Application
This repository contains a multi-layer application which was built for demonstration purposes.
It contains a collection of patterns and services which are used in enterprise applications.
– Layered architecture
– Dependency injection using AutoFac
– Test-driven design
– EntityFramework code-first database context
– UnitOfWork and repository pattern
– Restful WCF service with JSON
– Diverse client technologies. Using DTOs to exchange information with the backend and ViewModels (MVVM) to bind model data to views.

Furthermore, the aim of this project was to show the interplay of the mentioned technologies, principles and practices.

### Missing points
– Authentication and authorization
– Cross-platform mobile clients
– Localization
– Input validation
– Filtering, grouping, sorting, paging of list items

### Helpful links

Generic repository pattern, unit of work, entity framework in MVC


Autofac for MVC


Autofac for WebApi


Using Web API 2 with Entity Framework 6


Dependency Injection in ASP.NET Web API 2


Exception Handling in ASP.NET Web API


Automated Testing of ASP.NET Web API and MVC applications


Creating WCF REST services


Using MVVMLight in a WPF application


Configuring Relationships with the Fluent API


ASP.NET Web API Exception Handling




Exception Handling in WebAPI


Consuming WCF Services in Xamarin



Custom WCF message formatters (NewtonsoftJsonBehavior)