Button type “button” vs. “submit”

type
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.

 

https://stackoverflow.com/questions/7117639/input-type-submit-vs-button-tag-are-they-interchangeable

https://stackoverflow.com/questions/37736056/button-type-button-vs-submit

https://stackoverflow.com/questions/290215/difference-between-input-type-button-and-input-type-submit

 

 

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.

https://forums.asp.net/t/1428325.aspx?debug%20web%20service%20project%20in%20same%20solution%20as%20web%20site%20project%20

 

 

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>();

 

https://stackoverflow.com/questions/17831011/how-to-initialize-ienumerableobject-that-be-empty-and-allow-to-concat-to-it

 

 

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;
config.Formatters.Remove(config.Formatters.XmlFormatter);

 

 

jquery detect textbox value change NOT based on user input

http://javascript.qahowto.com/jquery-detect-textbox-value-change-NOT-based-on-user-input-javascript-jquery-f4dfd4

https://stackoverflow.com/questions/16048084/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:

[DataContract]
public class NewspaperDTO
{
    public NewspaperDTO(Newspaper newspaper)
    {
        this.Name = newspaper.Name;
        this.Image = newspaper.Image;
        this.Link = newspaper.Link;
        this.Encoding = newspaper.Encoding;
    }

    [DataMember]
    public string Name { get; set; }

    [DataMember]
    public string Image { get; set; }

    [DataMember]
    public string Link { get; set; }

    [DataMember]
    public string Encoding { get; set; }
}

And then in your service:

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

 

https://stackoverflow.com/questions/7161333/why-does-my-wcf-service-not-use-my-entity-model/7161377#7161377

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

http://techbrij.com/generic-repository-unit-of-work-entity-framework-unit-testing-asp-net-mvc

Autofac for MVC

http://techbrij.com/autofac-ioc-container-asp-net-mvc-di

Autofac for WebApi

http://docs.autofac.org/en/latest/integration/webapi.html

Using Web API 2 with Entity Framework 6

http://www.asp.net/web-api/overview/data/using-web-api-with-entity-framework/part-1

Dependency Injection in ASP.NET Web API 2

http://www.asp.net/web-api/overview/advanced/dependency-injection

Exception Handling in ASP.NET Web API

http://www.asp.net/web-api/overview/error-handling/exception-handling

Automated Testing of ASP.NET Web API and MVC applications

https://robdmoore.id.au/blog/2013/02/02/automated-testing-of-asp-net-web-api-and-mvc-applications/

Creating WCF REST services

http://www.codeproject.com/Articles/571813/A-Beginners-Tutorial-on-Creating-WCF-REST-Services

Using MVVMLight in a WPF application

http://www.dotnetcurry.com/wpf/1037/mvvm-light-wpf-model-view-viewmodel

Configuring Relationships with the Fluent API

https://msdn.microsoft.com/en-us/data/jj591620.aspx

ASP.NET Web API Exception Handling

http://weblogs.asp.net/fredriknormen/asp-net-web-api-exception-handling

Mvc4CustomErrorPage

https://github.com/13daysaweek/Mvc4CustomErrorPage/tree/master/ThirteenDaysAWeek.Mvc4CustomErrorPage.Web/Views

Exception Handling in WebAPI

http://www.codeproject.com/Articles/733512/Exception-Handling-in-WebAPI

Consuming WCF Services in Xamarin

http://www.nullskull.com/a/10476775/xamarin-cross-platform-application-consuming-wcf–part-1.aspx

http://nullskull.com/a/10476786/xamarin-cross-platform-application-consuming-wcf–part-2.aspx

Custom WCF message formatters (NewtonsoftJsonBehavior)

https://github.com/carlosfigueira/WCFSamples/tree/master/MessageFormatter/MessageFormatter/JsonNetMessageFormatter

http://stackoverflow.com/questions/8082231/custom-behavior-wont-register-in-my-web-config