HTML Helpers in MVC
Dotnet, DotnetCore, Azure, C#,VB.net, Sql Server, WCF, MVC ,Linq, Javascript and Jquery
30 April 2024
HTML Helpers in MVC
@Html.TextBox
@Html.Password
@Html.TextArea
@Html.CheckBox
@Html.RadioButton
@Html.DropDownList
@Html.ListBox
@Html.Hidden
@Html.Display
@Html.Editor
@Html.ActionLink
@Html.BeginForm
@Html.Label
Example of TextBox() in Razor view
@Html.TextBox("txtEmplpyeeName", "", new { @class = "form-control" })
Html Result
<input class="form-control" id="txtUserName" name="txtEmplpyeeName" type="text" value="">
Convert DataTable to List In C#
Convert DataTable to List In C#
You can achieve in below three ways
Using a Loop.
Using LINQ.
Using a Generic Method.
Using Linq
List<Student> studentList = new List<Student>();
studentList = (from DataRow dr in dt.Rows
select new Student()
{
StudentId = Convert .ToInt32 (dr["StudentId"]),
StudentName = dr["StudentName"].ToString(),
Address = dr["Address"].ToString(),
MobileNo = dr["MobileNo"].ToString()
}).ToList();
Eager Loading, Lazy Loading
Eager Loading, Lazy Loading
Eager Loading helps you to load all your needed entities at once; i.e., all your child entities will be loaded at single database call. This can be achieved, using the Include method, which returs the related entities as a part of the query and a large amount of data is loaded at once.
User usr = dbContext.Users.Include(a => a.UserDetails).FirstOrDefault(a => a.UserId == userId);
Lazy Loading
It is the default behavior of an Entity Framework, where a child entity is loaded only when it is accessed for the first time. It simply delays the loading of the related data, until you ask for it.
User usr = dbContext.Users.FirstOrDefault(a => a.UserId == userId);
Kestrel Server in Dotnet
Kestrel Server in Dotnet
Kestrel is a cross-platform web server for ASP.NET Core. Kestrel is the recommended server for ASP.NET Core, and it's configured by default in ASP.NET Core project templates.
ASP.NET Core project templates use Kestrel by default when not hosted with IIS. In the following template-generated Program.cs, the WebApplication.CreateBuilder method calls UseKestrel internally:
var builder = WebApplication.CreateBuilder(args);
When to use which Service, Singleton, Scoped and Transient
When to use which Service, Singleton, Scoped and Transient
Singleton approach => We can use this for logging service, feature flag (to on and off module while deployment), and email service,
Scoped approach => This is a better option when you want to maintain a state within a request,
Transient approach => Use this approach for the lightweight service with little or no state.
Scoped Approach in detail
The same instance lives for the entire scope of that request, for example; let's suppose one controller has two parameters, both are the objects of the same "Sample" class, then both the objects will share the same instance across the request,
Partitioning in SQL Server(Performance Improvement)
Partitioning in SQL Server(Performance Improvement)
Used to divide large tables or indexes into smaller , more manageable pieces, yet treat them as single entity.
Types
- Partition Function
- Partition Scheme
- Table and Index partitioning
Await example in C#
Await example in C#
using System;
using System.Threading.Tasks;
class Program {
private static string result="test123";
static void Main() {
SaySomething();
Console.WriteLine(result);
}
static async Task<string> SaySomething() {
await Task.Delay(5);
Console.WriteLine("test");
result = "Hello world!";
Console.WriteLine(result);
return “Something”;
}
}
Output
test123
test
Hello world!
Subscribe to:
Posts (Atom)
Implementing OAuth validation in a Web API
I mplementing OAuth validation in a Web API Implementing OAuth validation in a Web API using C# typically involves several key steps to sec...
-
ViewBag, ViewData, TempData and View State in MVC ASP.NET MVC offers us three options ViewData, ViewBag and TempData for passing data from...
-
// Export Datatable to Excel in C# Windows application using System; using System.Data; using System.IO; using System.Windows.Forms; ...