Q & A - Asp.Net Questions & Answers

 

Q&A 1.

What is the difference between ViewBag and ViewData in MVC?

ViewBag is a wrapper around ViewData, which allows to create dynamic properties. Advantage of viewbag over viewdata is that, in ViewBag no need to typecast the objects as in ViewData.

Q&A 2.

Explain TempData in Asp.Net MVC?

TempData is again a key, value pair as ViewData. This is derived from TempDataDictionary. TempData can keep data for the duration of an HTTP request, in other words, it can keep live data between two consecutive HTTP requests.
TempData only works with the current and subsequent request. TempData uses a session variable to store the data. This requires typecasting in view.

Q&A 3.

What are HTML Helpers in Asp.Net MVC?

HTML Helpers are like html controls, by using razor syntax @html and its extension methods we can easily add html tags into our web page instead of writing html tags manually. HTML Helpers returns the HTML string which can be directly rendered to HTML page.

Q&A 4.

What are ActionResult in MVC?

ActionResult is used to represent the action method result, ie. return type for any ActionMethod in Asp.Net MVC.

Q&A 5.

What is File return type in Asp.Net MVC?

The MVC framework have native support for the System.Web.MVC.Controller.File controller overload method, which provide return type of a file by a name or stream or byte array.

Q&A 6.

Explain FileResult in mvc?

FileResult is an abstract base class for all the other file return type classes FileContentResult, FilePathResult, or  FileStreamResult. FileResult allows users to download file from Asp.Net MVC server.

Q&A 7.

Explain four different types of FileResult in Asp.Net MVC.

Asp.Net MVC FileResult types -

FileContentResult : Sends the contents of a binary file to the response, use this when you want to use a byte array to access the file.

return new FileContentResult(byteArray, “image/jpeg”);

FilePathResult : Returns a file on disk when you must access via a file path. In the FilePathResult you can return a File type or a FileStreamResult.

return new FilePathResult(virtualFilePath, System.Net.Mime.MediaTypeNames.Application.Octet);

FileStreamResult : Sends a file stream out to the response.

return new FileStreamResult(new MemoryStream(document.Data), document.ContentType);

Q&A 8.

Can a view be shared across multiple controllers?

Yes, we can share a view across multiple controllers. We can put the view in the "Shared" folder.

Q&A 9.

What is Default Route in MVC?

Default Route: The default ASP.NET MVC project templates add a generic route that uses the following URL convention to break the URL for a given request into three named segments.

URL: "{controller}/{action}/{id}"
This route pattern is registered using MapRoute() extension method of RouteCollection class in mvc route table.

Q&A 10.

What is Validation Summary in Asp.Net MVC?

The Validation Summary helper method generates an unordered list of all validation error messages that are found in Model State Dictionary object. It can also be used to display custom error messages.


Related Quiz Content

x
This website is using cookies to make user experience of the site better. More info. OK