Skip to main content

Posts

Showing posts from March, 2018

What Is the difference between View and Partial View?

What Is the difference between View and Partial View? View - 1.       View contains the layout page 2.       Before any view is rendered, viewstart page is rendered 3.       View might have markup tags like body, html, head, title, Meta etc. 4.       View is not lightweight as compare to Partial View Partial View- 1.       Partial View does not contain the layout page 2.       Partial view does not verify for a viewstart.cshtml page. 3.       Partial view is designed specially to render within the view and just because of that it does not consist any mark up 4.       We can pass a regular view to the RenderPartial method

What Are Advantages and Disadvantages of MVC model?

What Are Advantages and Disadvantages of MVC model? Advantages - 1.       Each MVC object has different responsibilities 2.       The development progresses in parallel 3.       Easy to manage and maintain your app code 4.       All classes and object are independent of each other Disadvantages - 1.       The model pattern is little complex 2.       It is little difficult to use MVC as like modern user interface. 3.       Inefficiency of data access in view

What beforFilter(), beforeRender() and afterFilter() functions do in Controller?

What beforFilter(), beforeRender() and afterFilter() functions do in Controller? beforeFilter () -This function is used to run before every action in the controller. Most of the programmer used to check valid session, user role and permissions. beforeRender () - This function is used to called after controller action logic and before the view is rendered. afterFilter () - This function is used to called after every controller action and after rendering is competed. It is the last controller method to run.

What Is Attribute based Routing?

What Is Attribute based Routing? MVC 5 supports a new type of routing  that called attribute routing. It used to define routes. Enable Attribute Routing - If you want to use Attribute Routing, you must enable it by calling MapMvcAttributeRoutes on the RouteCollection. public class RouteConfig {     public static void RegisterRoutes ( RouteCollection routes )     {         routes . IgnoreRoute ( "{resource}.axd/{*pathInfo}" );                //Enables Attribute Routing         routes . MapMvcAttributeRoutes ();     } } Defining a Route - A route attribute has to be defined on top of an action method or on the top of a controller. The Example looks like, public class HomeController : BaseController {   [ Route ( "User/GetUsers" )]   public Act...

What Is ASP.NET MVC Routing ?

What Is Routing? The MCV Routing is a pattern matching system that matches  all browser’s incoming requests  to the  registered URL patterns  residing in the  RouteTable . When the MVC application starts, it registers  patterns  to the  RouteTable  to tell the  routing engine  to give a  response to the requests  that  match these patterns . An application has only one  RouteTable . Routes can be configured in  RouteConfig  class. Multiple custom routes can also be configured. The route must be registered in  Application_Start  event in the  Global.ascx.cs  file. Each MVC application has default routing for the default  HomeController . We can also set custom routing and the  RouteConfig  class. The three segments that is important for routing is  - {controller}/{action}/{id} RouteConfig class An example for Register Routes - public class ...

Where the Routing rules are defined in an ASP.Net MVC Application?

Where the routing rules are defined in an ASP.Net MVC Application? In Application_Start event in Global.asax The example looks like, public class MvcApplication : System . Web . HttpApplication {     protected void Application_Start ()     {         GlobalConfiguration . Configure ( WebApiConfig . Register );         FilterConfig . RegisterGlobalFilters ( GlobalFilters . Filters );         RouteConfig . RegisterRoutes ( RouteTable . Routes );         BundleConfig . RegisterBundles ( BundleTable . Bundles );     } }

What Are Filters in MVC?

Filters is basically used for authentication, authorization, validate or errors log before and after a controller action executes. Different Types of Filters Are Available i.e. 1.       Actions Filter 2.       Authorization filters 3.       Result filters 4.       Exception filters Action Filters - Action filters are used to implement logic that gets executed before and after a controller action executes. The Action filters have following - 1.       Output Cache- Used for caches the output of a controller action for a specified amount of time. 2.       Handle Error - Used for handles raised errors when a controller action executes. 3.       Authorize – Used to enables you to restrict access to a particular user role and its permission. Example for Output Cache –   [ HttpGet ] O...