Tuesday 21 March 2017

MVC interview questions Part-8

1. Ques: What is the strongly typed view in ASP.NET MVC? What are the main advantage of using strongly ?
Answer:
The view which bind with any model is called as strogly typed view. You  can bind any class as model to view.You can access model properties on  that view. You can use data associated with model to render controls.
You can bind custom types as well as primitive types like string, array, list etc.

public ActionResult View1()
{
  UserModel obj = new UserModel();
  return view(obj)
}

In view
  @Html.DisplayFor(modelItem => item.TotalWorkHours)

Again Main advantage of using strongly typed view is - You can same  object during posting view. So What ever values assigned to controls  associated models property. You can access in post action

Main advantage of using strongly typed view is -
  • You can use automatic scaffolding 
  • IntelliSense support 
  • Compile time type checking

2. Ques: What are the advantages of weak typing over strong typing?
Answer:
Weak Typing :
  • Requires less programing effort as the compiler or interpreter implicitly performs certain kinds of type conversions. So applications can be built in a rapid manner.
  • Fewer errors are caught at compile time. Many bugs are caught at run-time. Requires more discipline while coding.
Strong Typing:
  • Strong/Static types provide constraints which helps to catch errors during compile time
  • Strong typing provide more opportunities for performance enhancements
  • Strong typed code is easy to understand
  • Limits the developer programming expressiveness.
  • Application development go more slowly.

3. Ques:  What is UpdateModel() in mvc?
Answer:
UpdateModel() is a Controller helper method that attempts to bind a bunch of different input data sources (HTTP POST data coming from a View, QueryString values, Session variables/Cookies, etc.) to the explicit model object you indicate as a parameter.

UpdateModel method to fetch data from view to controller. UpdateModel is the method which is generics type and takes parameter of model type.


No comments:

Post a Comment

Thank you for comment