Skip to Content

TheBlogReaders.com

Salesforce.com, PHP, MySQL, Javascript, Ajax, Htacces

MVC Interview Questions and Answers For Graduates Part-2

Be First!

MVC-Diagram11.What are Actions in ASP.Net MVC?
Actions are the methods in Controller class which is responsible for returning the view or json data. Action will mainly have return type : “ActionResult” and it will be invoked from method : “InvokeAction()” called by controller.

12.What is Attribute Routing in ASP.Net MVC?
ASP.NET Web API supports this type routing. This is introduced in ASP.Net MVC5. In this type of routing, attributes are being used to define the routes. This type of routing gives more control over classic URI Routing. Attribute Routing can be defined at controller level or at Action level like :

[Route(“{action = TestCategoryList}”)] – Controller Level
[Route(“customers/{TestCategoryId:int:min(10)}”)] – Action Level
How to enable Attribute Routing?
Just add @Model.CustomerName the method : “MapASP.Net MVCAttributeRoutes()” to enable attribute routing as shown below:

public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute(“{resource}.axd/{*pathInfo}”);
//enabling attribute routing
routes.MapASP.Net MVCAttributeRoutes();
//convention-based routing
routes.MapRoute
(
name: “Default”,
url: “{controller}/{action}/{id}”,
defaults: new { controller = “Customer”, action = “GetCustomerList”, id = UrlParameter.Optional }
);
}

13.Explain JSON Binding?
JavaScript Object Notation (JSON) binding support started from ASP.Net MVC3 onwards via the new JsonValueProviderFactory, which allows the action methods to accept and model-bind data in JSON format. This is useful in Ajax scenarios like client templates and data binding that need to post data back to the server.

14.Explain Dependency Resolution?
Dependency Resolver again has been introduced in ASP.Net MVC3 and it is greatly simplified the use of dependency injection in your applications. This turn to be easier and useful for decoupling the application components and making them easier to test and more configurable.

15.Explain Bundle.Config in ASP.Net MVC4?
“BundleConfig.cs” in ASP.Net MVC4 is used to register the bundles by the bundling and minification system. Many bundles are added by default including jQuery libraries like – jquery.validate, Modernizr, and default CSS references.

16.How route table has been created in ASP.NET ASP.Net MVC?
Method : “RegisterRoutes()” is used for registering the routes which will be added in “Application_Start()” method of global.asax file, which is fired when the application is loaded or started.

17.Which are the important namespaces used in ASP.Net MVC?
Below are the important namespaces used in ASP.Net MVC –

System.Web.ASP.Net MVC
System.Web.ASP.Net MVC.Ajax
System.Web.ASP.Net MVC.Html
System.Web.ASP.Net MVC.Async

18.What is ViewData?
Viewdata contains the key, value pairs as dictionary and this is derived from class : “ViewDataDictionary”. In action method we are setting the value for viewdata and in view the value will be fetched by typecasting.

19.What is the difference between ViewBag and ViewData in ASP.Net MVC?
ViewBag is a wrapper around ViewData, which allows to create dynamic properties. Advantage of viewbag over viewdata will be : In ViewBag no need to typecast the objects as in ViewData. ViewBag will take advantage of dynamic keyword which is introduced in version 4.0. But before using ViewBag we have to keep in mind that ViewBag is slower than ViewData.

20.Explain TempData in ASP.Net MVC?
TempData is again a key, value pair as ViewData. This is derived from “TempDataDictionary” class. TempData is used when the data is to be used in two consecutive requests, this could be between the actions or between the controllers. This requires typecasting in view.

(187)

Previous
Next

Leave a Reply