Tag: ASP.NET MVC

How to accept HTML Form Data in a ASP.NET Web API Action Method ?

There are times when you might want to create an endpoint in ASP.NET WebAPI that can handle the HTML form data posted as x-www-form-urlencoded. One of the options is to use the model binding concept.   In this case , the model should have the names of the keys that are passed in the HTTP request. The MediaFormatters are used to extract the data from…

How to return Http Status Code from ASP.NET Web API Controller ?

There are times when you might want to return the Http Status code from an action method of a ASP.NET Web Api Controller. One of the simplest way of doing this is using the CreateResponse method of the HttpRequestMessage as shown below. The sample below demonstrates how to return the status code 304 and 200 based on the last modified date of the employee record….

How to get the Relative Server Path in ASP.NET Web API ?

In ASP.NET MVC , we can use the Server.MapPath or Request.MapPath to get the relative path of the server for a file. For example , The fileName would be the absolute path of the file. How to get the Relative Server Path in ASP.NET Web API ? You can use the HostingEnvironment.MapPath defined in System.Web.Hosting to get the relative path of the file as shown…

How to Add Web API to existing ASP.NET MVC Project ?

There are times when you might want to add Web API project to one of your existing ASP.NET MVC project instead of creating a new one. How to Add Web API to existing ASP.NET MVC Project ? You can easily do that by installing it from NuGet. Simply open the Package Console Manager and run the following command. Install-Package Microsoft.AspNet.WebApi

How to find if the request is from Ajax in ASP.NET MVC?

It is easy to find out if the actual request came from Ajax or is it a normal request in ASP.NET MVC. In the controller, one can use the Request.IsAjaxRequest method to find this. How to find if the request is from Ajax in ASP.NET MVC? Below is a sample code snippet demonstrating how to find if the request is from Ajax in ASP.NET MVC?

Difference between Html.EditorFor and Html.TextboxFor in ASP.NET MVC?

If you are working on Web Application development using ASP.NET MVC, you would come across the Html.EditorFor and Html.TextboxFor in the Razor View. What is the Difference between Html.EditorFor and Html.TextboxFor in ASP.NET MVC? The Html.TextboxFor creates a textbox with the input type of text. It will always render the input textbox. The EditorFor is a kind of smart helper method. This will render the…

What is the Difference between Repository and Service Layer in ASP.NET MVC?

Repository pattern, Unit of Work and Service Layer is one of the most commonly used word or technique especially when you are working on the ASP.NET MVC project. What is the Difference between Repository and Service Layer in ASP.NET MVC? These are the common Design pattern terms used in the ASP.NET MVC project. The Repository is a layer that provides additional abstraction on the data…

Liked this content?. Please spread the word :)