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.
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.
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.
What are ActionResult in MVC?
ActionResult is used to represent the action method result, ie. return type for any ActionMethod in Asp.Net MVC.
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.
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.
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);
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.
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.
This route pattern is registered using MapRoute() extension method of RouteCollection class in mvc route table.
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.