Important ASP.NET MVC interview questions
If you’re planning to attend a .NET Interview, and now you think, where should I focus to get prepared for ASP.NET MVC?. Then I am bringing out this article, to make sure that you qualify. I am listing here my top 20 ASP.NET MVC questions and their answers.
MVC is an architecture and is handled by three objects Model-View-Controller.
Model– It is responsible for maintaining data. You can bind the values from the database or a static one to the model and can list out the result in the view. the business logic implementation also takes place.
View– its simple what we see on the website. Apart from it we can play with razor view and performs oops feature.
The Controller–The respective controller responds within the model and choose a view to render that display the user interface.
using System.Web.Mvc;
Advantages:
a.Multiple view support, partial view, razor view.
b.Lightweight.
c.less coded.
d.Easy testing.
e.ViewBag, ViewData, TempData .
f.Different controllers and their unique features with excellent validation and authentication features.
a. Request -requests are mapped to route tables
b.Routing -The first to start with appstart-RouteConfig -RegisterRoutes -MapRoute .later depending on the page the controller and its associated actions are called.
c.fetching -UrlRoutingModule” searches the route table to create “RouteData” object which has the details of which controller and action to invoke
d.Requesting-outeData” object is used to create the “RequestContext
e.Controller-MvcHandler
f.Action -sql database
g.Model- sql database (bindn the values in model)
h.View -The html codes (design )
i.Result
1.PartialviewResult (Partialview): return a part of webpage from an action
2.RedirectResult (Redirect) -redirect to any controller and action method depending on the URL
3.RedirectToRouteResult (RedirectToAction, RedirectToRoute)-redirects to any existing actions
4.ContentResult (Content)-return HTTP content type like text/plain
5.jsonResult (json)-json message
6.javascriptResult (javascript)-returns javascript code
7.FileResult (File)-binary output
8.EmptyResult-return void
9.ViewResult – return a webpage from an action
10. ViewResult (View):This return type is used to return a web page from an action method.
derived from System.Attribute
to execute logic while MVC action is executed or its executing.
OutputCache(Duration = 20)]
public ActionResult Index()
{
return View ();
}
ViewData
Derived from ViewDataDictionary class.
Pass data from controller to view.
It is available for the current request only.
Requires typecasting for complex data types.
If redirection occurs, then its value becomes null.
ViewBag
Its dynamic(return type)
ViewBag is a dynamic property that takes advantage of the new dynamic features in C# 4.0
It is also available for the current request only.
It doesn’t require typecasting for the complex data type.
If redirection occurs, then its value becomes null.
TempData
Derived from TempDataDictionary class
Pass data from the current request to the next request(different action)
It helps to maintain the data when we move from one controller to another controller or from one action to another action
It requires typecasting
As the name itself its a part of the content that we want to make visible each time it loads.
example:
let’s consider there’s a user page and we want to reload only the users list , Then we can create a partial view and then we can reload just the part of the page which keeps on changing as shown in the pic.
Just it saves the time to load the page and give easiness to the coder as well.It also makes the page to load faster as instead of loading the whole page we just load a partial page.
Just like controls in ASP.NET, HTML helpers are used to creating or modifying HTML. Its lightweight, dynamic, and easy to use.
Yes, you can. You just need to install the npm and then you can.
Razor is an example of dynamic view available in MVC.With the Razor view now you are able to write C# code and make your suitabke changes.It helps a lot while binding the list values and other dynamic values from the controller.
Concept of “view engines” – which are the pluggable modules that implement different template syntax options.
why razor?
a.It gives you Intelligent and so quite helpful.
b.Testable
c.easiness
d.Dynamic with oops feature
Just a way to divide or “isolate” the modules of large applications in multiple or separated MVC.
Yes , you can and there you can add auditing features.
**Comment below to know more about auditing..
Add below like configuration in config inside
<connectionStrings>
<add name="Excel03ConString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR={1}'" />
<add name="Excel07ConString" connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties='Excel 12.0;HDR={1};IMEX=1'" />
</connectionStrings>
and then you can carry out the coding only at the controller level
**You can mail or comment to know about importing and exporting to excel.
Automatic code generation framework for ASP.NET Web applications. You can scaffold for
Create– creating a new record
Delete– delete link with delete record
Details-displays theand an input field
Edit-edit link, you can update the link on the pop-up screen
List-you can view the result in the list form.
Disadvantages:
1.Its less responsive
2. Complex results cant be obtained.
3.Extra codes.
4.simple view and logic only do support.
**Developers are not advisable to use it always
a. Bundling
Combining multiple (js) files or (CSS) files as a unit, rather than making individual requests.
b. Minification
Squeezing of the js and CSS files is called minification.It removes unwanted space, unused variables, repeated variables, repeated codes etc.
**Comment below how to achieve with Sitefinity, MVC, etc. Also, you can know more with a number of the ways you can do.
ASP.Net MVC has an attribute called “HandleError” that provides built-in exception filters.
steps to include them.
open FilterConfig class
Add
filters.Add(new HandleErrorAttribute());
in RegisterGlobalFilters
open global.asax
add
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
BundleConfig.RegisterBundles(BundleTable.Bundles);
in Application_Start()
It lists out all the detailed summary as a list for any failed validations occurring on the page and then generates an unordered list (ul element) of validation messages that are in the ModelStateDictionary object.
HandleErrorAttribute allows you to use a custom page for this error
[HandleError]
public class HomeController: Controller
{
[HandleError]
public ActionResult Index()
{
s= getdata();
throw new ApplicationException();
return view(“Index”);
}
}
1.Hidden Field: u can add a hidden field in the view @html.hiddenfor()
2.Cookies:storing the data but that data should be small.
HttpCookie cookie = new HttpCookie(“myNEWCookie”);
cookie.Value = “This is test cookie”;
this.ControllerContext.HttpContext.Response.Cookies.Add(cookie);
3.Query String=using “?”:
HttpCookie cookie = this.ControllerContext.HttpContext.Request.Cookies[“TestCookie”];
4.ViewData
5.ViewBag
6.TempData
ActionResult is a class that helps in creating a decoupled application.
Instead of returning a specific type of result action method returns an object of type ActionResult.ActionResult is a class that represents the result of an action method.
Cross-Site Request Forgery(CSRF) : Its adding script to our fields which might be dangerous. To avoid we use ValidateAntiForgeryToken attribute to an action method.
[ValidateAntiForgeryToken()]
Thank you! That’s all in ASP.NET MVC interview questions
And Also, visit our related posts in the below sections.
Jquery: Just know more about the HTTP before using any ajax operation
C Tutorial: Let’s learn in a much easier way
Encapsulation protects abstraction.
C#- Programming Guide | Starting Phase Learning(1)
8 steps to a Reliable facebook graph api in website
Mumbai, often referred to as the financial capital of India, is a hub for businesses and industries. With countless corporate…
When it comes to security services in Noida, there are several reputable companies that cater to various needs. Let me…
Are you tired of dealing with tooth decay, gum problems, and expensive dental treatments? Look no further! Steel Bite Pro…
In the world of fine jewelry, oval moissanite rings have emerged as a captivating choice for those seeking elegance and…
Noida, located in the state of Uttar Pradesh, is a fast-growing hub of digital marketing agencies in India. Choosing the…
As we move into 2023, the world of motorcycles in India is set to see some exciting changes. Manufacturers are…
Leave a Comment