HTML Helper is just a method that returns a HTML string. The string can represent any type of content that you want. For example, you can use HTML Helpers to render standard HTML tags like HTML <input>, <button> and <img> tags etc. You can also create your own HTML Helpers to render more complex content such as a menu strip or an HTML table for displaying database data.
Sr. Software Engineer. Having 7+ years of experience in software development. Asp.net, MVC, Json, JavaScript, JQuery, Ajax, CSS, HTML, C, C#, Linq, CanvasJS, Bootstrap, QT, Web API, .Net Core, Node JS.
Monday, 27 July 2015
Differentiation SingleOrDefault() vs FirstOrDefault() in MVC
Single() | SingleOrDefault() | First() | FirstOrDefault() | |
---|---|---|---|---|
Description | Returns a single, specific element of a sequence | Returns a single, specific element of a sequence, or a default value if that element is not found | Returns the first element of a sequence | Returns the first element of a sequence, or a default value if no element is found |
Exception thrown when | There are 0 or more than 1 elements in the result | There is more than one element in the result | There are no elements in the result | Only if the source is null (they all do this) |
When to use | If exactly 1 element is expected; not 0 or more than 1 | When 0 or 1 elements are expected | When more than 1 element is expected and you want only the first | When more than 1 element is expected and you want only the first. Also it is ok for the result to be empty |
List of Global.asax events in mvc.
protected void Application_Start(object sender, EventArgs e)
{
}
protected void Session_Start(object sender, EventArgs e)
{
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
}
protected void Application_AuthenticateRequest(object sender,EventArgs e)
{
}
protected void Application_Error(object sender, EventArgs e)
{
}
protected void Session_End(object sender, EventArgs e)
{
}
protected void Application_End(object sender, EventArgs e)
{
}
protected void Application_Start()
{
}
{
}
protected void Session_Start(object sender, EventArgs e)
{
}
protected void Application_BeginRequest(object sender, EventArgs e)
{
}
protected void Application_AuthenticateRequest(object sender,EventArgs e)
{
}
protected void Application_Error(object sender, EventArgs e)
{
}
protected void Session_End(object sender, EventArgs e)
{
}
protected void Application_End(object sender, EventArgs e)
{
}
protected void Application_Start()
{
}
How many web.config files can have in a web application(Project)..??
You may have multiple Web.Config files in one Asp.Net Application, but only One Per Folder.
Wednesday, 1 July 2015
What are the different types of Results in MVC (.Net)?
There are 11 different response types which can be sent to the end user :-
Example:-
1. View Result: -
public ActionResult Home()
{
return View();
}
2. Partial View Result :-
Public ActionResult AboutUs()
{
return PartialView("Hi");
}
3. Json Result :-
Public ActionResult Home()
{
return Json("hello from JSON");
}
- ViewResult - Renders a specified view to the response stream
- PartialViewResult - Renders a specified partial view to the response stream
- EmptyResult - An empty response is returned
- RedirectResult - Performs an HTTP redirection to a specified URL
- RedirectToRouteResult - Performs an HTTP redirection to a URL that is determined by the routing engine, based on given route data
- JsonResult - Serializes a given object to JSON format
- JavaScriptResult - Returns a piece of JavaScript code that can be executed on the client
- ContentResult - Writes content to the response stream without requiring a view
- FileContentResult - Returns a file to the client
- FileStreamResult - Returns a file to the client, which is provided by a Stream
- FilePathResult - Returns a file to the client
Example:-
1. View Result: -
public ActionResult Home()
{
return View();
}
2. Partial View Result :-
Public ActionResult AboutUs()
{
return PartialView("Hi");
}
3. Json Result :-
Public ActionResult Home()
{
return Json("hello from JSON");
}
Subscribe to:
Posts (Atom)