What is the primary purpose of TempData in ASP.NET Core?
4 phương ánCó giải thích
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Đáp án đúng: "To store data for a short period between two consecutive HTTP requests.". TempData dùng để chuyển dữ liệu ngắn hạn từ request này sang request kế tiếp, điển hình là thông báo sau khi lưu form: action POST gán TempData rồi redirect, request GET sau đọc ra hiển thị và giá trị bị xoá sau khi đọc (trừ khi gọi Keep hoặc Peek). "To store data for the duration of a single HTTP request." sai vì dữ liệu chỉ sống trong một request là ViewData, ViewBag hay HttpContext.Items, chúng mất khi request kết thúc nên không qua được redirect. "To store data persistently across multiple requests." sai vì lưu bền qua nhiều request cần session, cookie hoặc cơ sở dữ liệu, TempData bị xoá ngay khi đã đọc. "To manage user sessions." sai vì phiên do middleware Session và ISession quản lý, TempData có thể chọn session làm nơi lưu nhưng không quản lý phiên.
Cùng chương 4
With AddTransient<EmailService, EmailService>(), injecting into a controller twice will produce:Có lời giảiCâu hỏiConsider this C# code: public IActionResult Save(Person person) { if (ModelState.IsValid) return Content("Valid"); return Content("Error"); } If no value for Age is passed and Age is int, what happens?Có lời giảiCâu hỏiConsider this C# code: public class Person { public int Age { get; set; } } public IActionResult Save(Person person) { if (!ModelState.IsValid) { return Content("Invalid!"); } return Content("OK"); } Input: Age = "abc"? What is the output?Có lời giảiCâu hỏiCả 24 câu của chủ đề24 câu