ASP.Net MVC Interview questions and Answers

    4 Votes

40) What are Scaffold templates in MVC?

Scaffolding in ASP.NET MVC is used to generate the Controllers,Model and Views for create, read, update, and delete (CRUD) functionality in an application. The scaffolding will be knowing the naming conventions used for models and controllers and views.

41) Explain the types of Scaffoldings.
Below are the types of scaffoldings –
  • Empty
  • Create
  • Delete
  • Details
  • Edit
  • List
42) Can a view be shared across multiple controllers? If Yes, How we can do that?

Yes, we can share a view across multiple controllers. We can put the view in the “Shared” folder. When we create a new MVC Project we can see the Layout page will be added in the shared folder, which is because it is used by multiple child pages.

43) What are the components required to create a route in MVC?

  • Name - This is the name of the route.
  • URL Pattern – Placeholders will be given to match the request URL pattern.
  • Defaults –When loading the application which controller, action to be loaded along with the parameter.

44) Why to use “{resource}.axd/{*pathInfo}” in routing in MVC?

Using this default route - {resource}.axd/{*pathInfo}, we can prevent the requests for the web resources files like - WebResource.axd or ScriptResource.axd from passing to a controller.

45) Can we add constraints to the route? If yes, explain how we can do it?

Yes we can add constraints to route in following ways –

  • Using Regular Expressions
  • Using object which implements interface - IRouteConstraint.

46) What are the possible Razor view extensions?

Below are the two types of extensions razor view can have –

  • .cshtml – In C# programming language this extension will be used.
  • .vbhtml - In VB programming language this extension will be used.

47) What is PartialView in MVC?

PartialView is similar to UserControls in traditional web forms. For re-usability purpose partial views are used. Since it’s been shared with multiple views these are kept in shared folder. Partial Views can be rendered in following ways –

  • Html.Partial()
  • Html.RenderPartial()

48) How we can add the CSS in MVC?

Below is the sample code snippet to add css to razor views –

<link rel="StyleSheet" href="/@Href(~Content/Site.css")" type="text/css"/>

49) Can I add MVC Testcases in Visual Studio Express?

No. We cannot add the test cases in Visual Studio Express edition it can be added only in Professional and Ultimate versions of Visual Studio.

50) What is the use .Glimpse in MVC?

Glimpse is an open source tool for debugging the routes in MVC. It is the client side debugger. Glimpse has to be turned on by visiting to local url link -

  • http://localhost:portname//glimpse.axd 

This is a popular and useful tool for debugging which tracks the speed details, url details etc.

51) What is the need of Action Filters in MVC?

Action Filters allow us to execute the code before or after action has been executed. This can be done by decorating the action methods of controls with MVC attributes.

52) Mention some action filters which are used regularly in MVC?

Below are some action filters used –

  • Authentication 
  • Authorization
  • HandleError
  • OutputCache

53) How can we determine action invoked from HTTP GET or HTTP POST?

This can be done in following way –

  • Use class – “HttpRequestBase” and use the method – “HttpMethod” to determine the action request type.

54) In Server how to check whether model has error or not in MVC?

Whenever validation fails it will be tracked in ModelState. By using property – IsValid it can be determined. In Server code, check like this –

// No Validation Errors

55) How to make sure Client Validation is enabled in MVC?

In Web.Config there are tags called – “ClientValidationEnabled” and “UnobtrusiveJavaScriptEnabled”. We can set the client side validation just by setting these two tags “true”, then this setting will be applied at the application level.

<add key="ClientValidationEnabled" value="true" /> 
<add key="UnobtrusiveJavaScriptEnabled" value="true" />

56) What are Model Binders in MVC?

For Model Binding we will use class called – “ModelBinders”, which gives access to all the model binders in an application. We can create a custom model binders by inheriting “IModelBinder”.

57) How we can handle the exception at controller level in MVC?

Exception Handling is made simple in MVC and it can be done by just overriding “OnException” and set the result property of the filtercontext object (as shown below) to the view detail, which is to be returned in case of exception.

protected overrides void OnException(ExceptionContext filterContext)
{ }

58) Does Tempdata hold the data for other request in MVC?

If Tempdata is assigned in the current request then it will be available for the current request and the subsequent request and it depends whether data in TempData read or not. If data in Tempdata is read then it would not be available for the subsequent requests.

59) Explain Keep method in Tempdata in MVC?

As explained above in case data in Tempdata has been read in current request only then “Keep” method has been used to make it available for the subsequent request.


60) Explain Peek method in Tempdata in MVC?

Similar to Keep method we have one more method called “Peek” which is used for the same purpose. This method used to read data in Tempdata and it maintains the data for subsequent request.

string A4str = TempData.Peek("TT").ToString();
Page 3 of 4

Popular Videos


How to improve your Interview, Salary Negotiation, Communication & Presentation Skills.

Got a tip or Question?
Let us know

Related Articles

C# Interview Questions
.Net Framework Interview Questions and Answers
ADO.Net Interview Questions and Answers for Freshers, Experienced
ASP.Net Interview Questions and Answers
WCF Interview Questions and Answers
ASP.Net Web API Interview Questions
Top 50 Entity framework interview questions & answers