controller

asp.net mvc controller post best practices

允我心安 提交于 2019-12-22 12:43:10
问题 I am bit confused about "best practice" controller using question. My typically code look public ActionResult Edit(int reportId,FormCollection formCollection) { try { var report = _dbContext.EmployeeReports.Find(reportId); if (TryUpdateModel(report)) { _employeeReportService.Update(report); return RedirectToAction("List"); } return View("Edit", report); } catch (Exception) { // some logging etc return RedirectToAction("List"); } Well, is better using "TryUpdateModel" or only "UpdateModel" or

Using TempData dictionary prevents RedirectToAction from working

陌路散爱 提交于 2019-12-22 12:36:19
问题 I want to add view model to TempData in order to pass it to another controller like this (referring to last 2 lines): [HttpPost("register")] public async Task<IActionResult> Register(RegisterViewModel rvm) { if (ModelState.IsValid) { var result = await _authManager.RegisterUserAsync(rvm.FullName, rvm.Email, rvm.Password); if (result.IsSuccessful) { return RedirectToAction("Login", "Home", new { message = result.Message }); } else { TempData["rvm"] = rvm; return RedirectToAction("Register",

How to call a method before the method of requested controller is executed : magento

安稳与你 提交于 2019-12-22 11:04:14
问题 I want to call a method before the execution of every and each controller's method. I don't want to go and call the method in every method. I just want to call it from one place and it will be called before any method of any controller in magento. And I am sure we can do this but I don't know how it can be accomplished. Please provide your suggestions. Hope we can resolve this or may some expert guys already resolved this. Thanks. 回答1: You need to create an Observer that binds to the

ASP.NET MVC - Job of Controllers

做~自己de王妃 提交于 2019-12-22 10:54:53
问题 I think I'm beginning to be confused with the job of a controller in MVC. I have a service that exposes five functions: list packages in queue get package delete package accept package deny package My ASP.NET MVC controller depends on this service, and can generally execute a service call on an Action. I'm happy so far. The second part is then building the ViewModel result. If I do this inside of the controller, the controller now has an exploding dependency list -- each action added

uninitialized constant for HomePresenter

僤鯓⒐⒋嵵緔 提交于 2019-12-22 10:45:20
问题 I'm trying to implement a HomePresenter to be used inside the home action of my Pages controller: # app/controllers/pages_controller.rb class PagesController < ApplicationController def home @presenter = Pages::HomePresenter.new(current_user) end ... end # app/presenters/pages/home_presenter.rb module Pages class HomePresenter def initialize(user) @user = user end ... end end My presenter specs pass without errors, but when I run the server and access the home page in Chrome, I get this:

JMeter While Controller

◇◆丶佛笑我妖孽 提交于 2019-12-22 09:57:48
问题 I have searched as crazy for the solution to my problem throughout the web, but none exist yet. My problem is that I have to check if I get specific text in HTTP request, which is in a while loop and if I do, then I should leave the loop and continue with the thread or stop the thread completely if text doesn't exist. I have set it up as follows: Thread Group .. While controller .. HTTP request .. Response Assertion Listener I used LAST in the while controller and set HTTP response to false

rails link_to remote with params

守給你的承諾、 提交于 2019-12-22 09:57:33
问题 I'd like to trigger a remote action for a model using a link. Basically all this link needs to do is trigger a method with one parameter. Here's my code: = link_to 'Move Up', reorder_collection_folder_path(@collection, folder), :reorder => :up, :remote => true This does trigger the Folders#reorder controller action as expected, but the :reorder param is not being passed through. My log says: Started GET "/collections/1/folders/1/reorder" for 127.0.0.1 at 2011-03-01 18:03:31 -0600 Processing

CodeIgniter call same function for all controllers

て烟熏妆下的殇ゞ 提交于 2019-12-22 09:48:36
问题 I'm developing an application, where the same function I'm writing for some controllers. So I wanted one common function for all controllers. Please help me out I've stucked up with this. The work would be more appreciated. 回答1: You can develop a helper or library. codeigniter version 2 : https://codeigniter.com/userguide2/general/creating_libraries.html codeigniter version 3 : https://codeigniter.com/user_guide/general/creating_libraries.html?highlight=library 回答2: You can create MY

How can I remove callbacks inserted by vendor code?

被刻印的时光 ゝ 提交于 2019-12-22 09:47:02
问题 A gem I am using inserts an after_save callback that I would like to remove. It seems to me it would be cleaner to delete a symbol from an array than to fix the problem with a monkeypatch. How can I access the array of callbacks? 回答1: class UserSession < Authlogic::Session::Base # Don't use cookie AuthLogic behaviour skip_callback :persist, :persist_by_cookie skip_callback :after_save, :save_cookie skip_callback :after_destroy, :destroy_cookie end 回答2: the after_save array is accessible via

Url Referrer is not available in WebApi 2 MVC project

最后都变了- 提交于 2019-12-22 09:40:15
问题 I have an MVC WebAPI 2 project with a Controllers controller. The Method I'm trying to call is POST (Create). I need to access the referring URL that called that method yet, no matter what object I access, the referring URL either doesn't exist in the object or is null. For example, I've added the HTTPContext reference and the following returns null : var thingythingthing = HttpContext.Current.Request.UrlReferrer; The Request object does not have a UrlReferrer property. This returns null as