Tag: ASP.NET
Building a ASP.NET Web API in Visual Studio 2015
This blog post will explain on how to create a Simple ASP.NET Web API using Microsoft Visual Studio 2015 and return an expose a List (Eg: List<Students>) over HTTP. This includes creating action methods and using them for get all students and get a particular student by id. How to create a Web API in Visual Studio 2015 and return a List over HTTP? Follow…
Asp.net GridView example using C#
Below is a sample code snippet for Asp.net GridView example using C#. The code snippet shows how to populate the GridView with a List of Employees. Asp.net GridView example using C# ASP.NET WebForms <asp:GridView ID=”GridView1″ runat=”server”> </asp:GridView> C# protected void Page_Load(object sender, EventArgs e) { List<Employee> employees = new List<Employee>(); employees.Add(new Employee { Name = “Test1”, Designtaion = “Software Engineer” }); employees.Add(new Employee { Name…
Providing Default Values for a Route in ASP.NET MVC
The default values are useful specially when the entered URL does not contain the items with in the pattern . In these scenarios , the URL can route to the default action or controller. Providing Default Values for a Route in ASP.NET MVC Below is a sample code snippet demonstrating the usage of the default values to the route. In the above example , if…
Retrieve Data from the Request Object in ASP.NET MVC
In ASP.NET MVC, the Request property defined within the controller can be used to retrieve the data about the request. They can be accessed easily in the controller. Some of the useful properties within the Request objects includes Request.QueryString – This is a NameValueCollection which can be used to access variable sent with this request using GET method. Request.Form – This is a NameValueCollection will…
How to retrieve the URL of the current Page in ASP.NET MVC 4 Controller ?
If you want to retrieve the URL of the current Page in a ASP.NET MVC 4 Controller , you can get it by using the AbsoluteUri property defined in the Request.Url class. How to retrieve the URL of the current Page in ASP.NET MVC 4 Controller ? using System; using System.Linq; using System.Web; using System.Web.Mvc; namespace MvcApplication1.Controllers { public class EmployeeController : Controller { //…
How to enable Tracing for a specific page in ASP.NET ?
In ASP.NET Web forms , you can enable the tracing for a specific page by adding the trace attribute to the Page element in the aspx page. How to enable Tracing for a specific page in ASP.NET ?
Entering preprocessor directive in ASP.NET MVC Razor View
Below is a sample code snippet that demonstrates how to add preprocessor directive in ASP.NET MVC Razor View .
Multiple types were found that match the controller Error in ASP.NET MVC
There are times when you get the error similar to the below message when you type the URL “Multiple types were found that match the controller named ‘Employee’. This can happen if the route that services this request (‘Abundantcode/{controller}/{action}/{id}’) does not specify namespaces to search for a controller that matches the request. If this is the case, register this route by calling an overload of…
5 Alternative ASP.NET MVC View Engines
If you a ASP.NET MVC Web developer , you would have noticed that by default ASP.NET MVC includes 2 View Engines “Razor View” and “ASPX View”. In this article , we will explore other different View Engines(third party) available in ASP.NET. 5 Alternative ASP.NET MVC View Engines 1. Spark Spark is a open source view engine for ASP.NET MVC projects as well as Castle MonoRail…
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…
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…
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…
How to set default value for Html.TextBoxFor in ASP.NET MVC ?
You can set the default value for the Html.TextBoxFor extension controls in ASP.NET MVC by specifying the Value property as shown below. How to set default value for Html.TextBoxFor in ASP.NET MVC ?
Layout = null vs. ignoring Layout Property in ASP.NET MVC
What does Layout=null and ignoring the Layout property within the View means ? This is pretty simple , Layout=null , the view does not use any layout and the layout of the page will be the one used within the view. Ignoring the Layout property is a different story . Sometimes , ViewStart file can be used with the Views folder to define the layout…
How to read a key from the Web.Config file in ASP.NET app using C# ?
If you want to read the values based on the key from the web.config file in your ASP.NET application using C# , you can use the WebConfigurationManager to do it. How to read a key from the Web.Config file in ASP.NET app using C# ? Assume that the configuration file contains the below values If you want to read the value of the key (“UserName”)…
HttpUnauthorizedResult in ASP.NET MVC
The ActionResult can take different values like View , PartialView, String etc, Another value that it can take is HttpUnauthorizedResult . The HttpUnauthorizedResult when returned from a View will force the user to login in. HttpUnauthorizedResult in ASP.NET MVC