Q6. Where are the routing rules defined in an asp.net MVC application?
Q7. Name a few different return types of a controller action method in MVC?
Q8. What is the difference between ViewResult() and ActionResult() in ASP.NET MVC?
Q9. Difference between @Html.TextBox and @Html.TextBoxFor
Q10. What is the testing framework you have used?
======================================================================
Q6. Where are the routing rules defined in an asp.net MVC application?
Answer:
Asp.net MVC - In Application_Start event in Global.asax
.netCore MVC - in Startup.cs, configure() methods. app.UseEndpoints middleware.
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
======================================================================
Q7. Name a few different return types of a controller action method in MVC?
Answer:
There 12 kinds of results in MVC,
at the top is “ActionResult” class which is a base class that can have 11 subtypes’ as listed below: -
- ViewResult - Renders a specified view to the response stream
- PartialViewResult - Renders a specified partial view to the response stream
- EmptyResult - An empty response is returned
- RedirectResult - Performs an HTTP redirection to a specified URL
- RedirectToRouteResult - Performs an HTTP redirection to a URL that is determined by the routing engine, based on given route data
- JsonResult - Serializes a given ViewData object to JSON format
- JavaScriptResult - Returns a piece of JavaScript code that can be executed on the client
- ContentResult - Writes content to the response stream without requiring a view
- FileContentResult -Returns a file to the client
- FileStreamResult - Returns a file to the client, which is provided by a Stream
- FilePathResult - Returns a file to the client
Knowledge bomb :
IHttpActionResult is a way for creating responses introduced in WebAPI2 but IActionResult is more leaned towards ASP.NET MVC for returning the result of an action method. Also IActionResult is widely used in .net Core as well.
======================================================================
Q8. What is the difference between ViewResult() and ActionResult() in ASP.NET MVC?
Answer:
- ActionResult is an abstract class.
- ViewResult derives from ActionResult. Other derived classes include JsonResult and PartialViewResult.
- The View() method returns a ViewResult.
- In case we want to return two types of data based on condition. In that case actionResult would be the choice.
======================================================================
Q9. Difference between @Html.TextBox and @Html.TextBoxFor
Answer:
Html.TextBox is not strongly typed and it doesn't require a strongly typed view meaning that you can hardcode whatever name you want as first argument and provide it a value:
@Html.TextBox("foo", "some value")
You can set some value in the ViewData dictionary inside the controller action and the helper will use this value when rendering the textbox (ViewData["foo"] = "bar").
Html.TextBoxFor is requires a strongly typed view and uses the view model:
@Html.TextBoxFor(x => x.Foo)
The helper will use the lambda expression to infer the name and the value of the view model passed to the view.
And because it is a good practice to use strongly typed views and view models you should always use the Html.TextBoxFor helper.
======================================================================
Q10. What is the testing framework you have used?
Answer:
Visual Studio default Testing template can be used for Unit testing. It can be used with Mock testing framework. It work on concept AAA
The AAA (Arrange, Act, Assert) pattern is a common way of writing unit tests for a method under test.

