Swagger is a simple yet powerful representation of your RESTful API. Once integrated with WEB API, it becomes easy to test the API without using any third-party tool. In this post, we will see how to add Swagger to ASP.NET Core Web API.
Read More
Bind RadioButton List in Angular 2
Earlier I posted about how to bind Select DropDown List in Angular 2 and Cascading DropDown List using Angular 2 covering some of the newest features of Angular 2 beta 8 release. And in this post, we will find out how to bind radiobutton list in Angular 2. At the time of writing this post, Angular 2 RC4 is the newest version.
Make index.html as startup file in ASP.NET Core
Many websites use index.htm(l) or default.htm(l) as their startup page as its easy to remember but ASP.NET Core by default doesn’t use any of them as startup file. To use them, you have to configure couple of things. So in this post, let’s see how to make index.html as startup file in ASP.NET Core.
Read More
Entity Framework Core InMemory provider with ASP.NET Core
One of the new feature of EF Core is, Entity Framework Core InMemory provider. It’s a new db Provider which holds everything in memory. There is no database written to disk. This is useful for unit testing entity framework DB operations as InMemory storage behaves same as the actual database storage. So you don’t have to connect and query to actual database. So in this post, let’s see how to configure and use Entity Framework Core InMemory provider with an ASP.NET Core Application.
Read More
How to Install ASP.NET Core And Create Your First Application
Finally, ASP.NET Core is out and there is lots of excitement among developers. As you might be knowing ASP.NET Core is completely a new framework and will definitely require some learning. In this post I will take you through about how to install ASP.NET Core along with tooling and then creating your first .NET Core application and ASP.NET Core application using dotnet cli tool. Read More
Accept only int value for ASP.NET Web API action method parameter
In this short post, find solution to how to accept only int value for ASP.NET Web API action method parameter. Below is an example of Web API action method which accepts an int type parameter. And it returns the same value as response.
// GET api/values/5 [HttpGet("{id}")] public string Get(int id) { return id.ToString(); }
So when you hit http://localhost:59845/api/values/5
, you get “5” returned in response. And when you hit http://localhost:59845/api/values/abc
, then you get “0” as returned. But what if, you want to accept only integer value and if input parameter is not “int” then return a 404 error.
With attribute routing, you can also define the data type constraint for parameter. So updated action method is,
// GET api/values/5 [HttpGet("{id:int}")] public string Get(int id) { return id.ToString(); }
So now when you hit http://localhost:59845/api/values/abc
, then you shall get 404 error. You can use any data type for route constraint as per your requirement.
Hope you like it. Stay tuned for more!.