ASP.Net MVC Interview questions and Answers

    4 Votes

61) What is Area in MVC?

Area is used to store the details of the modules of our project. This is really helpful for big applications, where controllers, views and models are all in main controller, view and model folders and it is very difficult to manage.

62) How we can register the Area in MVC?
When we have created an area make sure this will be registered in “Application_Start” event in Global.asax. Below is the code snippet where area registration is done –
protected void Application_Start() 
{ 
AreaRegistration.RegisterAllAreas(); 
}
63) What are child actions in MVC?

To create reusable widgets child actions are used and this will be embedded into the parent views. In MVC Partial views are used to have reusability in the application. Child action mainly returns the partial views.

64) How we can invoke child actions in MVC?

ChildActionOnly” attribute is decorated over action methods to indicate that action method is a child action. Below is the code snippet used to denote the child action –

[ChildActionOnly] 
public ActionResult MenuBar() 
{ 
//Logic here 
return PartialView(); 
}

65) What is Dependency Injection in MVC?

It’s a design pattern and is used for developing loosely couple code. This is greatly used in the software projects. This will reduce the coding in case of changes on project design so this is vastly used.

66) Explain the advantages of Dependency Injection (DI) in MVC?

Below are the advantages of DI –

  • Reduces class coupling 
  • Increases code reusing 
  • Improves code maintainability 
  • Improves application testing

67) Explain Test Driven Development (TDD) ?

TDD is a methodology which says, write your tests first before you write your code. In TDD, tests drive your application design and development cycles. You do not do the check-in of your code into source control until all of your unit tests pass.

68) Explain the tools used for unit testing in MVC?

Below are the tools used for unit testing –

  • NUnit
  • xUnit.NET
  • Ninject 2
  • Moq

69) What is Representational State Transfer (REST) mean?

REST is an architectural style which uses HTTP protocol methods like GET, POST, PUT, and DELETE to access the data. MVC works in this style. In MVC 4 there is a support for Web API which uses to build the service using HTTP verbs.

70) How to use Jquery Plugins in MVC validation?

We can use dataannotations for validation in MVC. If we want to use validation during runtime using Jquery then we can use Jquery plugins for validation.

Eg: If validation is to be done on customer name textbox then we can do as –

$('#CustomerName').rules("add", {
required: true,
minlength: 2,
messages: {
required: "Please enter name",
minlength: "Minimum length is 2"
}
});

71) How we can multiple submit buttons in MVC?

Below is the scenario and the solution to solve multiple submit buttons issue.

Scenario –

@using (Html.BeginForm(“MyTestAction”,”MyTestController”)
{

<input type="submit" value="MySave" />
<input type="submit" value="MyEdit" />


}

Solution :

Public ActionResult MyTestAction(string submit) //submit will have value either “MySave” or “MyEdit”
{
// Write code here
}

72) What are the differences between Partial View and Display Template and Edit Templates in MVC?

  • Display Templates – These are model centric. Meaning it depends on the properties of the view model used. It uses convention that will only display like divs or labels.
  • Edit Templates – These are also model centric but will have editable controls like Textboxes.
  • Partial View – These are view centric. These will differ from templates by the way they render the properties (Id’s) Eg : CategoryViewModel has Product class property then it will be rendered as Model.Product.ProductName but in case of templates if we CategoryViewModel has List<Product> then @Html.DisplayFor(m => m.Products) works and it renders the template for each item of this list.

73) Can I set the unlimited length for “maxJsonLength” property in config?

No. We can’t set unlimited length for property maxJsonLength. Default value is - 102400 and maximum value what we can set would be – 2147483644.

74) Can I use Razor code in Javascript in MVC?

Yes. We can use the razor code in javascript in cshtml by using <text> element.

<script type="text/javascript">
@foreach (var item in Model) {
<text>
//javascript goes here which uses the server values
</text>
}
</script>

75) How can I return string result from Action in MVC?

Below is the code snippet to return string from action method –

public ActionResult TestAction() {
return Content("Hello Test !!");
}

76) How to return the JSON from action method in MVC?

Below is the code snippet to return string from action method –

public ActionResult TestAction() {
return JSON(new { prop1 = “Test1”, prop2 = “Test2” });
}

77) How we can override the action names in MVC?

If we want to override the action names we can do like this –

[ActionName("NewActionName")]
public ActionResult TestAction() {
return View();
}
Page 4 of 4

Popular Videos

communication

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