Tag: ASP.NET MVC
IController in ASP.NET MVC
Every Controller in ASP.NET MVC is extended from the Controller abstract class which in turn implements the IController interface. The IController interface is defined in the System.Web.Mvc namespace of the .NET Framework. The IController interface contains the method Execute which is called when the user enter the URL which involves the implemented controller class. The controller classes that you create can implement IController but you…
How to render without encoding in ASP.NET MVC Razor View ?
Are you looking to render a string in ASP.NET Razor View without encoding ? If yes , you could use the Html.Raw helper methods to achieve this. How to render without encoding in ASP.NET MVC Razor View ? Below is a sample code snippet to demonstrate the usage of Html.Raw in ASP.NET MVC.
Installing ASP.NET MVC and Prerequisites
To develop ASP.NET MVC Applications , you need Visual Studio to be installed . The Visual Studio contains all the necessary stuffs to get started . You can download Visual Studio 2012 or Visual Studio 2010 and install it from Microsoft Download Center. Download Visual Web Developer 2012 from Visual Studio website The Visual Studio 2012 has the necessary and latest ASP.NET MVC templates to…
How to Create a View in ASP.NET MVC ?
Every Web Applications needs to have the UI through which the user can interact with . You can easily create a View in ASP.NET MVC by following the below steps. How to Create a View in ASP.NET MVC ? 1. Right Click on the Action Method in the Controller and click “Add View” in the context menu. 2. In the Add View Dialog , give…
How to retrieve the IP Address in ASP.NET MVC Web Application ?
If you want to retrieve the client’s IP Address in ASP.NET MVC , there are couple of ways that you can achieve this. How to retrieve the IP Address in ASP.NET MVC Web Application ? 1. Use the Request.ServerVariables[“REMOTE_ADDR”] which will retrieve the IP address in ASP.NET 2. You could also use the Request.UserHostAddress to achieve the same. Below is a sample controller sourecode demonstrating…
CS1502: The best overloaded method match for System.Web.WebPages.WebPageExecutingBase.WriteSystem.Web.WebPages.HelperResult)’ has some invalid arguments Error in ASP.NET MVC
If you are getting the below error message in ASP.NET MVC Web Application, you can resolve it by looking at the methods that renders the partial view in the screen. “Server Error in ‘/’ Application. ——————————————————————————– Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code…
RegisterArea in ASP.NET MVC
In the previous article, we provided you an overview of the areas in ASP.NET MVC. When a new area is created in ASP.NET MVC, a file with the area name suffixed by AreaRegistration will be created. In the example as described in the previous article, the AbundantcodePayrollAreaRegistration.cs contains the following This class contains the RegisterArea method which is used to register the route with the…
How to add a Controller in ASP.NET MVC Application ?
Controller is one of the main component in the MVC Architecture. When the user enters the URL , the requests are first handled by the controllers which then identifies the right view to be rendered. The controllers class is inherited from System.Web.Mvc.Controller class and it contains various action methods. How to add a Controller in ASP.NET MVC Application ? To add the controller in ASP.NET…
How to find Absolute Path of a Folder in a Controller in ASP.NET MVC 4 ?
There are times when you want to access a file from the Application Folder which you need access to . In this case , you might need the complete path of the file that you are trying to access . How to find Absolute Path of a Folder u in a Controller in ASP.NET MVC ? You can use the Server.MapPath method that is defined…
How to define MaxLength property for a textbox in ASP.NET MVC Razor View?
Below is a sample code snippet which demonstrates how to define MaxLength property for a textbox in ASP.NET MVC Razor View.
How to create RadioButton in ASP.NET MVC ?
The ASP.NET MVC Framework provides the helper method RadioButton and RadioButtonFor to create radio button in ASP.NET MVC web page. How to create RadioButton in ASP.NET MVC ? Below is a sample sourecode snippet demonstrating how to create RadioButton in ASP.NET MVC . View @model MvcApplication1.Models.EmployeeVM @{ ViewBag.Title = “Index”; } <h2>@ViewBag.ApplicationTitle</h2> @Html.Label(“AbundantCode-a Programming Directory”) @Html.RadioButtonFor(Model => Model.IsActive, true) @Html.RadioButtonFor(Model => Model.IsActive, false)
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
ASP.NET MVC and View State
The ASP.NET Web Forms includes the Server Controls which generally retains the state of the controls in the hidden field called _ViewState . Does ASP.NET MVC have View State ? The concept of server controls in ASP.NET Web Forms is different from the ASP.NET MVC . The ASP.NET MVC does not maintain the _ViewState in the HTML pages that is rendered by Razor or ASPX…
How to Change the Browser in Visual Studio 2012 to test the ASP.NET MVC Application ?
When you are testing your ASP.NET MVC Project from Visual Studio 2012 , you might want to see how the Webpage looks on other browsers too. How to Change the Browser in Visual Studio 2012 to test the ASP.NET MVC Application ? You can change the browser from Visual Studio 2012 by changing the browser from the list of installed and available browsers from the…
What are the Advantages of the ASP.NET MVC Framework ?
ASP.NET MVC has some advantages over the traditional ASP.NET Web Forms development . In this article , we will have a look at some of the advantages of the ASP.NET MVC Framework . What are the Advantages of the ASP.NET MVC Framework ? SoC – Separation of Concerns Separation of Concern is one of the core advantages of ASP.NET MVC . The MVC framework provides…
Using MapRoute for Registering Routes in ASP.NET MVC 4
The previous article explained How to Create and Register a Route in ASP.NET MVC using the Route class and add it to the RouteCollection. This article will explain how to use MapRoute class for registering routes in ASP.NET MVC 4. Using MapRoute for Registering Routes in ASP.NET MVC 4 The MapRoute is defined in the RouteCollection and can be used without creating the instance of…
What is the difference between RouteLink and ActionLink in ASP.NET MVC ?
This article will cover some of the key differences between the RouteLink and ActionLink helper methods in ASP.NET MVC. What is the difference between RouteLink and ActionLink in ASP.NET MVC ? The Html.ActionLink renders the hyperlink tag to the specified controller action which uses the Routing API internally to generate URL. This renders the Anchor tag that links to the action method. The ActionLink method…
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….
Creating Areas in ASP.NET MVC Application
The ASP.NET MVC Framework has the concept of “Areas” which allows the developers to organize the functional module of the web application. For Example, the modules like administration, student’s data, exam/test, results can be each area in the Application. The Area in the ASP.NET MVC project has a folder structure which includes controllers, views, Models etc. and allows the developers to keep them separate from…
No parameterless constructor defined for this object error in ASP.NET MVC Project
If you are getting an error similar to the one shown below in your ASP.NET MVC Project , you could verify your Model. No parameterless constructor defined for this object error in ASP.NET MVC Project Server Error in ‘/’ Application. No parameterless constructor defined for this object. An unhandled exception occurred during the execution of the current web request. Please review the stack trace for…