Tag: ASP.NET MVC

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…

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…

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…

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…

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…

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