ASP.NET MVC Interview Questions : Part 3

 

Q.1  How to pass model to the view?

  • We can pass model first to controller action method then controller pass it to view. 
  • We can pass this using ViewData, ViewBag, TempData, strongly typed model object.
  • When we pass data to view using ViewBag, ViewData, TempData then that view becomes loosely-coupled.
  • We can better understand by given example below:


Q.2  What is strongly typed views and how do we create them?

  • The view which bind with any model is called as Strongly-typed view.
  • Strongly Typed views provides compile-time error checking as well as intelligence.
  •  If we misspell the property or method name, then it will known at compile time rather than at run-time. 
  • We need to pass model object as a parameter to view() method. 
  • Eg. protected internal ViewResult View(object model) - This is the overloaded version of View() method which we can use to pass data from controller to view.


Q.3  How we can change the startup controller name and action name?

  • We can change both by endpoints configuration as below :


Q.4  What is routing?

  • Routing is nothing but navigation between different pages.
  • But as we know Angular is SPA so here the navigation is between one view to another view.
  • The router provides the function to do routing operations.
  • The route refers current active route.
  • Routing eliminated need of mapping URL with physical file.


Q.5  What is viewdata?

  • It is used to transfer data from controller to view. 
  • ViewData is of dictionary type so it contains key-value pair where each key is a string.
  • TypeCasting, Null checks are required.


Q.6  What is ViewBag?

  • It is used to transfer data from controller to view.
  • ViewBag is of dynamic type.
  • TypeCasting, Null checks are not required.



Thank You!!!

For more understanding watch below video :

Comments

Popular posts from this blog

Day 3 : JavaScript

SQL Concepts-1

ASP .NET Session Management