Posts

Showing posts from December, 2016

Explain what is the difference between View and Partial View?

View: It contains the layout page. Before any view is rendered, viewstart page is rendered. View might have markup tags like body, html, head, title, meta etc. View is not lightweight as compare to Partial View. Partial View: It does not contain the layout page. Partial view does not verify for a viewstart.cshtml.We cannot put common code for a partial view within the viewStart.cshtml.page. Partial view is designed specially to render within the view and just because of that it does not consist any mark up. We can pass a regular view to the RenderPartial method.

Explain what is routing in MVC? What are the three segments for routing important?

Routing is a mechanism to process the incoming url that is more descriptive and give desired response. In this case, URL is not mapped to specific files or folder as was the case of earlier days web sites. There are two types of routing (after the introduction of ASP.NET MVC 5). Convention based routing:  to define this type of routing, we call MapRoute method and set its unique name, url pattern and specify some default values. Attribute based routing:  to define this type of routing, we specify the Route attribute in the action method of the controller. Routing is the URL pattern that is mappped together to a handler,rounting is responsible for incoming browser request for particular MVC controller. In other ways let us say routing help you to define a URL structure and map the URL with controller. There are three segments for routing that are important, ControllerName ActionMethodName Parammeter i.e:  ControllerName/ActionMethodName/{ParamerName} and als...

What are Action Filters in MVC?

Action Filters: Action Filters are additional attributes that can be applied to either a controller section or the entire controller to modify the way in which action is executed. These attributes are special .NET classes derived from System.Attribute which can be attached to classes, methods, properties and fields. ASP.NET MVC provides the following action filters: Output Cache:  This action filter caches the output of a controller action for a specified amount of time. Handle Error:  This action filter handles errors raised when a controller action executes. Authorize:  This action filter enables you to restrict access to a particular user or role.

What are Filters in MVC?

In MVC, controllers define action methods and these action methods generally have a one-to-one relationship with UI controls such as clicking a button or a link, etc. For example, in one of our previous examples, the UserController class contained methods UserAdd, UserDelete, etc. But many times we would like to perform some action before or after a particular operation. For achieving this functionality, ASP.NET MVC provides feature to add pre and post action behaviors on controller's action methods. Types of Filters: ASP.NET MVC framework supports the following action filters: Action Filters:  Action filters are used to implement logic that gets executed before and after a controller action executes. We will look at Action Filters in detail in this chapter. Authorization Filters:  Authorization filters are used to implement authentication and authorization for controller actions. Result Filters:  Result filters contain logic that is executed before and after a view...

List out different return types of a controller action method?

There are total nine return types we can use to return results from controller to view.  The base type of all these result types is ActionResult. ViewResult (View) : This return type is used to return a webpage from an action method. PartialviewResult (Partialview) : This return type is used to send a part of a view which will be rendered in another view. RedirectResult (Redirect) : This return type is used to redirect to any other controller and action method depending on the URL. RedirectToRouteResult (RedirectToAction, RedirectToRoute):  This return type is used when we want to redirect to any other action method. ContentResult (Content) : This return type is used to return HTTP content type like text/plain as the result of the action. jsonResult (json):  This return type is used when we want to return a JSON message. javascriptResult (javascript):  This return type is used to return JavaScript code that will run in browser. FileResult (File): ...

Is it True that ASP.NET Web API has Replaced WCF?

It's a misconception that ASP.NET Web API has replaced WCF. It's another way of building non-SOAP based services, for example, plain XML or JSON string, etc. Yes, it has some added advantages like utilizing full features of HTTP and reaching more clients such as mobile devices, etc. But WCF is still a good choice for following scenarios: If we intended to use transport other than HTTP, e.g. TCP, UDP or Named Pipes Message Queuing scenario using MSMQ One-way communication or Duplex communication

What are the Advantages of Using ASP.NET Web API?

Using ASP.NET Web API has a number of advantages, but core of the advantages are: It works the HTTP way using standard HTTP verbs like  GET ,  POST ,  PUT ,  DELETE , etc. for all CRUD operations Complete support for routing Response generated in JSON or XML format using  MediaTypeFormatter It has the ability to be hosted in IIS as well as self-host outside of IIS Supports Model binding and Validation Support for OData and more....

What is ASP.NET Web API?

ASP.NET Web API is a framework that simplifies building HTTP services for broader range of clients (including browsers as well as mobile devices) on top of .NET Framework. Using ASP.NET Web API, we can create non-SOAP based services like plain XML or JSON strings, etc. with many other advantages including: ·          1 . Create resource-oriented services using the full features of HTTP ·          2. Exposing services to a variety of clients easily like browsers or mobile devices, etc.