MVC Q&A

1. What is MVC
View : it the User Interface
Controller : it manages all the web request and as per the request calls the appropriate view to render.
Models : it refers to application data, which is passed to view.
2. Types of ActionResult ?
a) Viewresult b) JsonResult c) EmptyResult d) PartialViewResult e)FileStreamResult
3. Difference between viewdata, viewbag and tempdata ?
a) viewdata :
-it is used to pass data from controller to view
-it is derived from viewDataDictionary Class
-it requires typecasting
b) viewbag:
-it is used to pass data from controller to view
-it is a dynamic property
-it does not requires typecasting
c) tempdata
– it is used to pass data from controller to controller
– it is derived from TempDataDictionary Class.
– it requires type casting.
Eg:
controller
public ActionResult Index()
{
var carobj = new car()
{
carname=”BMW”;
carprice =”10000″
}
ViewData[“car”] = carobj;
ViewBag.car= carobj;
TempData[“car”]=carobj;
return View();
}
view:
var carobj = ViewData[“car”] as car; //typecasting
@ViewData[“car”] .carname
@viewBag.car.carname
4. what is partial view?
partial view are the reusable views, like for the common header footer we can use partial views.
it is just like the usercontrol in asp.net
5. features of asp.net mvc 4 ?
a) Enhancements of default project templates
b) WebApi
c) bundling and minification
d) New Mobile Project template added
6. how to do validation in an asp.net mvc application ?
by using data annotations we can do validations
7. what is razor in mvc ?
Razor is a serverside markup language which is embedded inside a view. it is very simple and easier to learn compared to traditional .aspx markup language.
the extension of razor files are .cshtml , .vbhtml

No comments:

Post a Comment