Tag: ASP.NET MVC

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…

UrlHelper.GenerateUrl in ASP.NET MVC

The UrlHelper.GenerateUrl in ASP.NET MVC can be used to return a string which contains the URL. UrlHelper.GenerateUrl in ASP.NET MVC The UrlHelper.GenerateUrl takes 7 parameters (overloaded). These parameters include RouteName ActionName ControllerName Route Values Route Collection Request Context Include Implicit Mvc Values Below is a sample code snippet demonstrating the UrlHelper.GenerateUrl

Difference between RenderBody, RenderPage and RenderSection in ASP.NET MVC

Difference between RenderBody, RenderPage and RenderSection in ASP.NET MVC The RenderBody can generally be found in the Layout page which is a kind of master page. Each Layout page can contain only one RenderBody method. It is like a Content Placeholder in ASP.NET WebForms. With the RenderPage, the content of the page can be filled by other pages. This takes the physical path of the…

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…

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…

Optional URL Segments in ASP.NET MVC

The developer can define the optional URL segment which need not be specified by the user when entering the URL. For example , assume the URL pattern “Abundantcode/{controller}/{action}/{id}” . In this pattern , the developer can make the id segment as optional by specifying them in the MapRoute method . Optional URL Segments in ASP.NET MVC Below is a code snippet demonstrating the usage of…

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…

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…

Specifying Text for Html.LabelFor in ASP.NET MVC Application

The Html.LabelFor helper method can be used to display label in the ASP.NET MVC View . The LabelFor takes the parameter of the property defined in the model to display the text . Specifying Text for Html.LabelFor in ASP.NET MVC ApplicationThe developers can use the DisplayAttribute for the property which is used in the System.ComponentModel.DataAnnotations namespace . For example , is the property name in…

How to Create and Register a Route in ASP.NET MVC ?

The routes for the ASP.NET MVC Web Application is defined in the RouteConfig.cs under the App_Start folder of the ASP.NET MVC 4 Project. The RouteConfig.CS contains the following code. The RouteConfig contains a static RegisterRoutes function which is called from the Global.asax file. The above method in the Global.asax is triggered when the application is started for the first time. How to Create and Register…

Liked this content?. Please spread the word :)