Category: ASP.NET

How to retrieve all the Errors from the ModelState in ASP.NET MVC ?

To display all the possible error messages from the ModelState in ASP.NET MVC , the developers would use the Html.ValidationSummary helper method in the View . How to get the list of all the Errors from the ModelState in ASP.NET MVC Controller ? The ModelState.Values property is a ICollection which contains the list of all the states which the developers can use to filter out…

Url.Action in ASP.NET MVC

The Url.Action method in ASP.NET MVC allows the developers to generate the fully qualified URL to an action method. It is defined in the namespace System.Web.Mvc. The Url.Action generates only the URL unlike the Html.ActionLink. Url.Action in ASP.NET MVC Below is a code snippet of the View demonstrating the Url.Action

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 Populate the DropDownList in ASP.NET MVC Razor View?

The DropDownList is one of the most useful controls that can be used in various scenarios that involves selecting the data from the list. The ASP.NET MVC Framework provides the Html.DropDownList and Html.DropDownListFor helper methods which can be used to create DropDownList. How to Populate DropDownList in ASP.NET MVC Razor View? Below is a sample source code demonstrating how to Populate DropDownList in ASP.NET MVC…

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…

Date DisplayFormat for Textbox in ASP.NET MVC

If you want to apply date display format to the textbox in ASP.NET MVC , you can achieve this through Data Annotations in the model. Date DisplayFormat for Textbox in ASP.NET MVC Below is a sample sourecode demonstrating the Date DisplayFormat for Textbox in ASP.NET MVC Razor View Model and Data Annotations The above annotations will display the textbox in the specified datetime format .

How to use RequireHttps in ASP.NET MVC ?

ASP.NET MVC has an attribute called RequireHttps which can be used to forces an unsecure HTTP request to pass through Https. How to use RequireHttps in ASP.NET MVC ? You can use RequireHttps by just placing the RequireHttps attribute on top of the Action Method in the Controller like an sample shown below.

How to Specify the Area name in ActionLink in ASP.NET MVC ?

Areas in ASP.NET MVC provides an option for the developers to separate the large ASP.NET MVC Web Application in to module grouping. When using the ActionLink in ASP.NET MVC , How do one mention the area names too ? How to Specify the Area name in ActionLink in ASP.NET MVC ? The Html.ActionLink has an parameter which accepts the Html Attributes , just specify the…

Open Source ASP.NET ecommerce Projects

There are plenty of ASP.NET ecommerce Projects or solutions available for the ASP.NET developers . In this article , we will list out some of the popular open source ASP.NET ecommerce solutions. DotShoppingCart 3.0 – Open Source Edition nopCommerce dashCommerce! Suteki Shop The DotShoppingCart 3.0 Community Edition is a open source ecommerce and CMS ( Content Management System). This project leverages some of the other…

Server.MapPath with usage of . , .. , ~ and / Characters in ASP.NET

When using Server.MapPath in ASP.NET, the developers can specify the characters as shown below. var path1 = Server.MapPath(“.”)var path2 = Server.MapPath(“..”)var path3 = Server.MapPath(“~”)var path4 = Server.MapPath(“/”) What is the difference between the above methods ? Assume that the website is installed in the path D:\WebApplications\Abundantcode and the root of the IIS is C:\Inetpub\wwwroot and assume that the current page is http://abundantcode.com/popularposts The path1 will…

JavaScript Unit Testing tools

There are plenty of Unit testing tools available which lets the developers to test their JavaScript code easily. In this article , we cover few of the popular JavaScript testing tools. JavaScript Unit Testing tools Karma Karma has the tagline “Spectacular Test Runner for JavaScript”. Karma is a very simple JavaScript Unit Testing tool which is built with node.JS. Karma lets the developers to run…

What are files with _ in ASP.NET MVC ?

When a new ASP.NET MVC Project is created , one might observe files that start with _ specially in the Views folder. What are files with _ in ASP.NET MVC ? The files that starts with _ are generally the Layouts which is normally placed in the /Views/Shared of the ASP.NET MVC project.

How to apply a Layout for a View in ASP.NET MVC ?

In the previous article , step by step procedure was provided on How to Create Layout in ASP.NET MVC Project ? . This article will explain how to apply a layout to a View in ASP.NET MVC. How to apply a Layout for a View in ASP.NET MVC ? The View has a property called “Layout” . This “Layout” property needs to be set in…

Passing Parameters to the ActionLink in ASP.NET MVC

There are times when the parameter has to be passed along with the URL from an ActionLink control in ASP.NET MVC. This can be done easily using the anonymous type which can be passed as the third parameter for the ActionLink helper method. Passing Parameters to the ActionLink in ASP.NET MVC Below is a sample code snippet demonstrating how to pass values to the ActionLink…

How to Access ModelState Property within the View of ASP.NET MVC ?

Most of the times , the ModelState property is used within the controller to verify if the model has valid data or not. But there are sometimes where you want to access the ModelState Property within the View in ASP.NET MVC Application. How to Access ModelState Property within the View of ASP.NET MVC ? If you need to access the ModelState property in the View…

How to Specify CSS Class Name for the ActionLink in ASP.NET MVC?

Below is a sample soucrecode demonstrating how to specify the CSS class Name for the ActionLink helper method in ASP.NET MVC. How to Specify CSS Class Name for the ActionLink in ASP.NET MVC? @model MvcApplication1.Models.EmployeeVM @{ if (@ViewContext.ViewData.ModelState.IsValid) { ViewBag.Title = “Index”; } } <h2>Abundant Code</h2> @Html.ActionLink(“Abundantcode.com – Primary source for Programming samples”, “Home”, new { @class = “Style1” })

ViewBag and DynamicObject in ASP.NET MVC

ViewBag is used in ASP.NET MVC to pass data from the controller to View . It is a dynamic object and is a member of the Controller class. Any dynamic property with its value can be assigned and later be used to retrieve it in the View. Below is a sample code snippet on the usage of the ViewBag to store the ApplicationTitle and later…

How to Create Layout in ASP.NET MVC Project ?

The ASP.NET MVC Project includes the templates to create a layout for the website . In order to create a layout in ASP.NET MVC project , follow the below steps How to Create Layout in ASP.NET MVC Project ? 1. Right Click on the View Folder and select “Add New Item” in the context menu. 2. In the Add New Item Dialog , select the…