public IActionResult Details(int?id) { //throw new Exception("Error in details view"); _logger.LogTrace("Trace Log"); _logger.LogDebug("Debug Log"); _logger.LogInformation("Information Log"); _logger.LogWarning("Warning Log"); _logger.LogError("Error Log"); _logger.LogCritical("Critical Log"); Employee model = _employeeRepository.GetEmployee(id.Value); if (model == null) { return(View("EmployeeNotFound", id.Value)); } HomeDetailsViewModel homeDetailsViewModel = new HomeDetailsViewModel() { EmployeeList = new List <Employee>() { model }, PageTitle = "Employee Details" }; return(View(homeDetailsViewModel)); }
//[Route("Home/Details/{id?}")] public ViewResult Details(int?id) { _logger.LogTrace("Trace Log"); _logger.LogDebug("Debug Log"); _logger.LogInformation("Information Log"); _logger.LogWarning("Warning Log"); _logger.LogError("Error Log"); _logger.LogCritical("Critical Log"); //throw new Exception("Error in Details View"); //form values--> route values --> query strings Employee employee = _employeeRepository.GetEmployee(id.Value); if (employee == null) { Response.StatusCode = 404; return(View("EmployeeNotFound", id.Value)); } HomeDetailsViewModel homeDetailsViewModel = new HomeDetailsViewModel() { Employee = employee, PageTitle = "Employee Details" }; return(View(homeDetailsViewModel)); }
public ViewResult Details(string id) { //throw new Exception("Error in Details View"); logger.LogTrace("Trace Log"); logger.LogDebug("Debug Log"); logger.LogInformation("Information Log"); logger.LogWarning("Warning Log"); logger.LogError("Error Log"); logger.LogCritical("Critical Log"); int employeeId = Convert.ToInt32(protector.Unprotect(id)); Employee employee = _employeeRepository.GetEmployee(employeeId); if (employee == null) { Response.StatusCode = 404; return(View("EmployeeNotFound", employeeId)); } HomeDetailsViewModel homeDetailsViewModel = new HomeDetailsViewModel() { //Employee = _employeeRepository.GetEmployee(id ?? 1), Employee = employee, PageTitle = "Employee Details" }; return(View(homeDetailsViewModel)); }
public ViewResult Details(int?Id) { // throw new Exception("Error in Details View"); _logger.LogTrace("Trace Log"); _logger.LogDebug("Debug Log"); _logger.LogInformation("Information Log"); _logger.LogWarning("Warning Log"); _logger.LogError("Error Log"); _logger.LogCritical("Critical Log"); Student student = _studentRepository.GetStudent(Id.Value); if (student == null) { Response.StatusCode = 404; return(View("StudentNotFound", Id.Value)); } HomeDetailsViewModel homeDetailsViewModel = new HomeDetailsViewModel { Student = student, PageTitle = "Details Page" }; return(View(homeDetailsViewModel)); }
public ViewResult Details(int?id) { Employee employee = _employeeRepository.GetEmployee(id); if (employee == null) { Response.StatusCode = 404; return(View("EmployeeNotFound", id)); } //id = 1; Employee model = employee;//_employeeRepository.GetEmployee(id??1); if (model.PhotoPath == null) { model.PhotoPath = "/images/Jeep.webp"; } else { model.PhotoPath = "~/images/" + model.PhotoPath; } //return View("~/MyViews/Test.cshtml"); //return View("MyViews/Test.cshtml"); //return View("../MyViews/Test.cshtml"); //this points Views/MyViews/Test.cshtml //return View("../../MyViews/Test"); //this relative path is from Views/Home folder. HomeDetailsViewModel homeDetailsViewModel = new HomeDetailsViewModel() { Employee = model, PageTitle = "Employee Details" }; return(View(homeDetailsViewModel)); }
public ViewResult Details(int?id) { var employee = _employeeRepository.GetEmployee(id.Value); if (employee == null) { Response.StatusCode = 404; return(View("EmployeeNotFound", id.Value)); } HomeDetailsViewModel homeDetailsViewModel = new HomeDetailsViewModel() { Employee = _employeeRepository.GetEmployee(id ?? 1), PageTitle = "Employee Details" }; //デフォルトでは規約に従って自分のコントローラー(Home)のアクション(Details)のViewに返す return(View(homeDetailsViewModel)); //規約以外のファイルを指定する。拡張子もいらない。拡張子つけたらエラーになる。 //return View("Test", model); //さらに、任意のフォルダの場合。拡張子が必要 //絶対パスは/MyViews...でもMyViewsでも~/MyViewsでもよい。 //プロジェクトルートが起点。 //return View("MyViews/Test.cshtml", model); //相対パスでさかのぼることもできる //return View("../../MyViews/Test"); }
public IActionResult Details(int id) { logger.LogTrace("Trace(跟踪) Log"); logger.LogDebug("Debug(调试) Log"); logger.LogInformation("信息(Information) Log"); logger.LogWarning("警告(Warning) Log"); logger.LogError("错误(Error) Log"); logger.LogCritical("严重(Critical) Log"); // throw new Exception("此异常发生在Details视图中"); Student student = _studentRepository.GetStudent(id); if (student == null) { Response.StatusCode = 404; return(View("StudentNotFound", id)); } //实例化HomeDetailsViewModel并存储Student详细信息和PageTitle HomeDetailsViewModel homeDetailsViewModel = new HomeDetailsViewModel() { Student = student, PageTitle = "学生详细信息" }; return(View(homeDetailsViewModel)); }
public IActionResult Details(int id) { logger.LogTrace("跟踪"); logger.LogDebug("调试"); logger.LogInformation("消息"); logger.LogWarning("警告"); logger.LogError("错误"); logger.LogCritical("严重"); Student student = _studentRepository.GetStudent(id); if (student == null) { Response.StatusCode = 404; return(View("StudentNotFound", id)); } HomeDetailsViewModel homeDetailsViewModel = new HomeDetailsViewModel() { Student = student, PaperTitle = "StudentDetails" }; //ViewData["PageTitle"] = "StudentDetails"; //ViewData["Student"] = student; //return View(student); //return View(); ViewBag.Title = "AAADetials"; return(View(homeDetailsViewModel)); }
public ViewResult Details(int?id) { //throw new Exception("Error in Details Page"); logger.LogInformation("{{LogInformation}}"); logger.LogWarning("{{LogWarning}}"); logger.LogCritical("{{LogCritical}}"); logger.LogDebug("{{LogDebug}}"); logger.LogError("{{LogError}}"); logger.LogTrace("{{LogTrace}}"); Employee employee = _employeeRepository.GetEmployee(id.Value); if (employee == null) { Response.StatusCode = 404; return(View("EmployeeNotFound", id.Value)); } HomeDetailsViewModel homeDetailsViewModel = new HomeDetailsViewModel() { Employee = employee, }; return(View(homeDetailsViewModel)); }
public IActionResult Details(int id) { //return Json(new { id="1", name="张三"}); //Student model = _studentRepository.GetStudent(1); //return Json(model); //ViewData["PageTitle"] = "学生的详情"; //ViewData["Student"] = model; //实例化HomeDetailsViewModel并存储Student详细信息和PageTitle Student student = _studentRepository.GetStudent(id); if (student == null) { Response.StatusCode = 404; return(View("StudentNotFound", id)); } HomeDetailsViewModel homeDetailsViewModel = new HomeDetailsViewModel() { Student = student, PageTitle = "学生详细信息" }; return(View(homeDetailsViewModel)); }
public IActionResult Details(int?id) { //throw new Exception("Test error"); _logger.LogTrace("Trace Log"); _logger.LogDebug("Debug Log"); if (id is null) { id = 1; } Employee employee = _employeeRepository.GetEmployee(id.Value); if (employee is null) { Response.StatusCode = 404; return(View("EmployeeNotFound", id.Value)); } HomeDetailsViewModel homeDetailsViewModel = new HomeDetailsViewModel { Employee = employee, PageTitle = "Details Page" }; return(View(homeDetailsViewModel)); }
public IActionResult Details(string id)//id is a route value Home/Details/?id=someid { #region testlogs //logger.LogTrace("Trace Log"); //logger.LogDebug("Debug Log"); //logger.LogInformation("Information Log"); //logger.LogWarning("Warning Log"); //logger.LogError("Error Log"); //logger.LogCritical("Critical Log"); #endregion int decryptedId = int.Parse(protector.Unprotect(id)); House house = _houseRepository.GetHouse(decryptedId); if (house == null) { Response.StatusCode = 404; return(View("HouseNotFound", id)); } HomeDetailsViewModel homeDetailsViewModel = new HomeDetailsViewModel() { House = house, PageTitle = "Details page" }; return(View(homeDetailsViewModel)); }
public ViewResult Details(int?id) { HomeDetailsViewModel homeDetailsViewModel = CreateHomeDetailsViewModel(id); ViewBag.PageTitle = "Song Details"; return(View(homeDetailsViewModel)); }
public ViewResult Details(int?id) { //Employee model = _employeeRepo.GetAnEmployee(1); //ViewBag.pageTitle = "Employee Details"; //return View(model); //throw new Exception("Disastrous error"); Employee employee = _employeeRepo.GetAnEmployee(id.Value); if (employee != null) { HomeDetailsViewModel vm = new HomeDetailsViewModel() { Employee = employee, title = "Employee Details", }; return(View(vm)); } else { Response.StatusCode = 404; return(View("Employee404", id.Value)); } }
public async Task <IActionResult> Details(int id, HomeDetailsViewModel model) { if (ModelState.IsValid) { var game = gameRepository.GetById(id); var user = await userManager.GetUserAsync(HttpContext.User); if (game == null) { Response.StatusCode = 404; return(View("NotFound")); } if (user == null) { return(View("NotFound")); } Memories memories = new Memories() { gameId = game.Id, Memory = model.Memories.Memory, UserId = user.Id, UserName = user.UserName, DatePosted = DateTime.Now }; memorieRepository.AddMemories(memories); return(RedirectToAction("details", new { id = game.Id })); } return(View(model)); }
public IActionResult Details(int id) { _logger.LogTrace("Trace log"); _logger.LogDebug("Debug log"); _logger.LogInformation("Information log"); _logger.LogWarning("Warning log"); _logger.LogError("Error log"); _logger.LogCritical("Critical log"); //throw new Exception("此异常发生在 Details 视图中"); var student = _studentRepository.GetStudent(id); if (student == null) { Response.StatusCode = 404; return(View("StudentNotFound", id)); } // 实例化 HomeDetailsViewModel 并存储 Student 详细信息和 PageTitle var homeDetailsViewModel = new HomeDetailsViewModel { Student = student, PageTitle = "学生详细信息" }; // 将ViewModel对象传递给View()方法 return(View(homeDetailsViewModel)); }
public ViewResult Get(string id) { //throw new Exception("Error in Details View"); _logger.LogTrace("LogTrace log"); _logger.LogDebug("LogDebug log"); _logger.LogInformation("LogInformation log"); _logger.LogWarning("LogWarning log"); _logger.LogError("LogError log"); _logger.LogCritical("LogCritical log"); /*Employee model = _employeeRepository.GetEmployee(id); * ViewData["PageTitle"] = "Details View"; * ViewData["Employee"] = model; * ViewBag.something = "something from home/details";*/ int employeeId = Convert.ToInt32(protector.Unprotect(id)); Employee employee = _employeeRepository.GetEmployee(employeeId); if (employee == null) { Response.StatusCode = 404; return(View("EmployeeNotFound", employeeId)); } HomeDetailsViewModel homeDetailsViewModel = new HomeDetailsViewModel() { Employee = _employeeRepository.GetEmployee(employeeId), PageTitle = "Employee Details" }; //return View(model); //return View("MyViews/Test.cshtml"); //return View("../../MyViews/Test"); return(View(homeDetailsViewModel)); }
//[Route("home/details/{id?}")] //[Route("details/{id?}")] //[Route("[action]/{id?}")] //[Route("{id?}")] public ViewResult Details(int?id) { //throw new Exception("Error in details view."); Employee employee = _employeeRepository.GetEmployee(id.Value); if (employee == null) { Response.StatusCode = 404; return(View("EmployeeNotFound", id.Value)); } // used the ?? null cohalescing operator //if (id < 1 || id > 3) //{ // id = 1; //} HomeDetailsViewModel homeDetailsViewModel = new HomeDetailsViewModel() { Employee = employee, PageTitle = "Employee Details vm" }; Employee model = _employeeRepository.GetEmployee(1); //ViewData["Employee"] = model; //ViewData["PageTitle"] = "Employee Details"; //ViewBag.Employee = model; ViewBag.PageTitle = "Employee Details"; //return View(model); // default use by NetCore - Views/*Controller Name w/ Controller* return(View(homeDetailsViewModel)); }
public ViewResult Details(int id) { logger.LogTrace("Trace(跟踪) Log"); logger.LogDebug("Debug(调试) Log"); logger.LogInformation("信息(Information) Log"); logger.LogWarning("警告(Warning) Log"); logger.LogError("错误(Error) Log"); logger.LogCritical("严重(Critical) Log"); //throw new Exception("在Details视图中抛出异常"); var student = _studentRepository.GetStudentById(id); //判断学生信息是否存在 if (student == null) { Response.StatusCode = 404; return(View("StudentNotFound", id)); } //实例化HomeDetailsViewModel并存储Student详细信息和PageTitle HomeDetailsViewModel homeDetailsViewModel = new HomeDetailsViewModel() { Student = student, PageTitle = "学生详情" }; //将ViewModel对象传递给View()方法 return(View(homeDetailsViewModel)); }
public ViewResult Details(string id) // String ID // 120 encryption and decryption { // throw new Exception("Creating an Exception"); // If ouer ID = NULL we just throw a 404 and as the user to go back or somthing // Decrypt the employee id using Unprotected method string decryptedId = protector.Unprotect(id); int decryptedIntId = Convert.ToInt32(decryptedId); var emp = _employeeRepository.GetEmployee(decryptedIntId); if (emp == null) { Response.StatusCode = 404; return(View("EmployeeNotFound", decryptedIntId)); } HomeDetailsViewModel homeDetailsViewModel = new HomeDetailsViewModel() { Employee = emp, PageTitle = "Employee Details", comments = commentRepository.GetAllCommentsOnEmployeeId(emp.Id.ToString()) }; return(View(homeDetailsViewModel)); //Employee LOL = _employeeRepository.GetEmployee(1); //ViewBag.PageTitle = "Employee Details"; //return View(LOL); }
public ViewResult Details(string id) { //return this.View("Test", this.employeeRepository.GetEmployee(1)); //return this.View("~/MyViews/Test.cshtml", this.employeeRepository.GetEmployee(1)); //return this.View("../Test/Update", this.employeeRepository.GetEmployee(1)); //return this.View("../../MyViews/Test", this.employeeRepository.GetEmployee(1)); int employeeId = Convert.ToInt32(this.protector.Unprotect(id)); var employee = this.employeeRepository.GetEmployee(employeeId); if (employee == null) { return(this.View("EmployeeNotFound", employeeId)); } else { var homeDetailsViewModel = new HomeDetailsViewModel { Employee = employee, PageTitle = "Employee Details" }; return(this.View(homeDetailsViewModel)); } }
public ViewResult Details(int?id) { logger.LogTrace("Trace Log"); logger.LogTrace("Debug Log"); logger.LogTrace("Information Log"); logger.LogTrace("Warning Log"); logger.LogTrace("Error Log"); logger.LogTrace("Critical Log"); Employee employee = _employeeRepository.GetEmployee(id.Value); if (employee == null) { Response.StatusCode = 404; return(View("EmployeeNotFound", id.Value)); } HomeDetailsViewModel homeDetailsViewModel = new HomeDetailsViewModel() { Employee = employee, PageTitle = "Employee Details" }; return(View(homeDetailsViewModel)); }
// ? 使 id 方法參數可以是空的 public ViewResult Details(int?id) { _logger.LogTrace(" Trace 追蹤 Log"); _logger.LogDebug("Debug 除錯 log"); _logger.LogInformation(" Information 資訊 Log"); _logger.LogWarning("Warning 警告 log"); _logger.LogError(" Error 錯誤 Log"); _logger.LogCritical("Critical 嚴重 log"); // GetStudentById 介面方法要重新定義,不然會報錯 var student = _studentRepository.GetStudentById(id); if (student == null) { Response.StatusCode = 404; return(View("StudentNotFound", (int)id)); } // Instantiate 實例化 HomeDetailsViewModel 並儲存 Student 詳細訊息和 PageTitle HomeDetailsViewModel homeDetailsViewModel = new HomeDetailsViewModel() { // 如果 id == null 則取第一筆 Student = _studentRepository.GetStudentById(id ?? 1), PageTitle = $"Student Details " }; return(View(homeDetailsViewModel)); }
//public JsonResult Details() //{ // Student model = _studentRepository.GetStudent(1); // // 返回学生的名字 // return Json(model); // //return _studentRepository.GetStudent(1).Name; // //return Json(new { id="1" ,name="张三"}); //} //[Route("{id?}")] public ViewResult Details(int?id) { HomeDetailsViewModel homeDetailsViewModel = new HomeDetailsViewModel() { Student = _studentRepository.GetStudent(id ?? 1), PageTitle = "学生详情信息" }; return(View(homeDetailsViewModel)); //Student model = _studentRepository.GetStudent(1); //将PageTitle和Student模型对象存储在VIewBag //我们正在使用动态属性PageTitle和Student //ViewBag.PageTitle = "学生详情信息"; //ViewBag.Student = model; //return View(model); // 返回学生的名字 //return View(model); //return View("Test"); // ViewData的使用 //ViewData["PageTitle"] = "学生详情"; //ViewData["Student"] = model; //return View(); //ViewBag的使用 }
public ViewResult Details(int?id) { //throw new Exception("Error in Details View"); logger.LogTrace("Trace Log"); logger.LogDebug("Debug Log"); logger.LogInformation("Information Log"); logger.LogWarning("warning Log"); logger.LogError("Error Log"); logger.LogCritical("Critical Log"); Employee employee = _employeeRepository.GetEmployee(id.Value); if (employee == null) { Response.StatusCode = 404; return(View("NotFoundPage", id.Value)); } HomeDetailsViewModel homeDetailsViewModel = new HomeDetailsViewModel() { Employee = _employeeRepository.GetEmployee(id ?? 1), PageTitle = "Employee Details" }; //ViewData["Employee"] = model; //ViewData["PageTitle"] = "Employee Details"; //ViewBag.Employee = model; //ViewBag.PageTitle = "Employee Details"; return(View(homeDetailsViewModel)); }
public ViewResult Details(int id) { //throw new Exception("Error in details"); logger.LogTrace("Trace Log"); logger.LogDebug("Debug Log"); logger.LogInformation("Information Log"); logger.LogWarning("Warning Log"); logger.LogError("Error Log"); logger.LogCritical("Critical Log"); Book book = _bookRepository.GetBook(id); if (book == null) { Response.StatusCode = 404; return(View("BookNotFound", id)); } HomeDetailsViewModel homeDetailsViewModel = new HomeDetailsViewModel() { Book = book, PageTitle = "Book Details" }; //Book model = _bookRepository.GetBook(1); return(View(homeDetailsViewModel)); }
public IActionResult Details(int categoryId) { HomeDetailsViewModel model = new HomeDetailsViewModel(); model.LoadModelData(_unitOfWork, categoryId); return(View(model)); }
public ViewResult Details(int id) { var allMemories = memorieRepository.GetAllMemories(); var game = gameRepository.GetById(id); var allGames = gameRepository.GetAllGames(); if (game == null) { return(View("NotFound")); } HomeDetailsViewModel model = new HomeDetailsViewModel() { Game = game, AllMemories = allMemories, AllGames = allGames, PageTitle = "Game's Details" }; if (allMemories != null) { foreach (var m in allMemories.ToList()) { model.ListMemories.Add(m); } return(View(model)); } return(View(model)); }
//to respect content negotiation use ObjectResult instead of JsonResult public ViewResult Details(int?id) { //throw new Exception("Error in details view"); logger.LogTrace("Trace Log"); logger.LogDebug("LogDebug"); logger.LogInformation("LogInformation"); logger.LogWarning("LogWarning"); logger.LogError("LogError"); logger.LogCritical("LogCritical"); Employee employee = _employeeRepository.GetEmployee(id.Value); if (employee == null) { Response.StatusCode = 404; return(View("EmployeeNotFound", id.Value)); } HomeDetailsViewModel homeDetailsViewModel = new HomeDetailsViewModel() { Employee = employee, PageTitle = "Employee details" }; return(View(homeDetailsViewModel)); }
public ViewResult Details(int?id) { //throw new Exception("Error in details view"); //var x = _employeeRepository.GetAllEmployee(); Employee employee = _employeeRepository.GetEmployee(id.Value); if (employee == null) { Response.StatusCode = 404; return(View("EmployeeNotFound", id.Value)); } HomeDetailsViewModel homeDetailsViewModel = new HomeDetailsViewModel() { Employee = employee,//_employeeRepository.GetEmployee(id??1), PageTitle = "Employee Details" }; //Employee model = _employeeRepository.GetEmployee(2); //default path is Views/Home // we use ../ to back one time from home to views //return View("test"); // we can also write the path with the extention if the file out of Views //return View("MyViews/test.cshtml"); //absolute path we can also use / or ~/ //return View("../Test/Update"); //relevant path we don't use the extention //ViewData["Employee"] = model; //ViewData["PageTitle"] = "Employee Details"; //ViewBag.Employee = model; //ViewBag.PageTitle = "Employee Details"; return(View(homeDetailsViewModel)); }