Asp .Net Core da Middleware bilan amaliy mashg’lot.
app.UseDefaultFiles();
app.UseStaticFiles();
app.UseFileServer();
Static file lar bilan ishlaydigan middlewarelar
app.UseRouting(); - rout bilan ishlaydigan middleware.
app.Use(async (context, next)=>
{
await context.Response.WriteAsync("Middleware 1 ");
await next();
});
//app.UseEndpoints(endpoints =>
//{
// endpoints.MapGet("/", async context =>
// {
// await context.Response.WriteAsync("Main page! ");
// });
// endpoints.MapGet("/Users", async context =>
// {
// await context.Response.WriteAsync("Users page! ");
// });
//});
Static file lar bilan ishlash.
Static file lar bilan ishlay oladigan middlewarelar-
App.UseStatikFiles().
App.UseDefaultFiles().
App.UseFileServer() – universali hisoblanadi
Delevoler Exception Page middleware
Configur methodida birinchi bo’lib pipeline ga qo’shilayotgan middleware bu DeveloperException degan middleware
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
MVC haqida.
MVC – Model View Controller – dasturni 3 ta mantiqiy qismlarga bo’luvchi arxitekturaviy pattern deyiladi.
Hozirgi vaqtda aksariyat tizimlar quyidagi 3 ta tizimdan iborat bo’ladi:
Presentation (UI) – foydalanuvchi interfasi.
Business Login – tizimning asosiy business logikasi saqlanadigan qatlam.
Data Access.
Controllerdan Viewga ma’lumot uzatish
Controllerdan Viewga ma’lumot uzatishning 3 xil yo’li mavjud :
ViewData
ViewBag
Strongly Typed Views
ViewData – aslida viewdata dictionary, string turidagi kalitni qabul qiladi.
Staff model = _staffRepository.Get(3);
ViewData[“staff”] = model;
ViewData[“title”] = “Staff Details”;
Ushbu ViewData key value per turidagi ma’lumot saqlanuvchi dictionary ekan, u dictionaryga controllerdan turib ma’lumotni beramiz va viewda shu kalit orqali ma’lumotni o’qib olamiz.
Viewda o’qib olish :
@ViewData[“title”]
@{
Var staff = ViewData[“staff”] as StaffManegement.Models.Staff;
}
Va foydalanish quyidagicha : @staff.Firstname , …
ViewBag – dynamic turidagi object.
ViewBag.title = “Staff Details”; uni viewda o’qib olish @ViewBag.title – shu orqali o’qib olinadi.
ViewData bilan ViewBag deyarli bir xil ularning farqi sintaksisda, ularni ishlatganimizda intellijenc ishlamaydi.
Do'stlaringiz bilan baham: |