controller

asp.net mvc Find Controller By Name With Area

三世轮回 提交于 2019-12-10 22:12:52
问题 My goal is to find a controller from it's name and area. I have successfully done this if my current httpContext is within the same Area as the to-be-found controller. However, I cannot get my call to the ControllerFactory to take Area into consideration. Here's my code: public static ControllerBase GetControllerByName(this HtmlHelper htmlHelper, string controllerName) { IControllerFactory factory = ControllerBuilder.Current.GetControllerFactory(); IController controller = factory

Controller redirect to different paths depending on previous page

对着背影说爱祢 提交于 2019-12-10 21:55:23
问题 Question: How I want to redirect to different path after create action, given if previous_page is ../reader/new goes to ../reader/blog/:id , whereas if previous_page is ../editor/new goes to ../editor/blog/:id . Explaination: I want to modify the controller actions so that it can redirect to different path depending on which page it comes from. For example, I have a reader , editor and blog model. Both reader and editor can create a blog . Here is the original blogs_controller : class

Call WebApi controller from another controller

一世执手 提交于 2019-12-10 21:53:13
问题 So I have two projects in my solution. Both are WebApi. I have controllers in both and I can call them from the client side - javascript. The problem is that I need to call a method in the controller of the second project from method in the controller of the first project. I also think I should state that the method I need to call is Post so I need to send it parameters as well. Is this possible at all? I heard about "RedirectToAction" method but I think this won't work in webapi. 回答1: You

Reuse `ui-route` controller that expects a `resolve`d parameter

拈花ヽ惹草 提交于 2019-12-10 21:37:30
问题 I want to be able to reuse my ui-router -wired controllers. They currently receive parameters from ui-router resolve to render their templates. Can I reuse those controllers without ui-router ? For example, I do this with ui-router : .controller('DetailController', function ($scope, detailData) { $scope.controllerDetail = detailData + "is awesome!"; }) .config(function ($stateprovider) { $stateprovider.state('detailState', { resolve: { detailData: function () { return "John Doe"; } },

Spring 3 MVC: Expose session scoped bean in MVC Controller method arguments

我的未来我决定 提交于 2019-12-10 21:03:45
问题 I want to pass a session-scoped domain bean around my controllers for consistency and simplicity - but this doesn't seem possible OOTB. Hope someone can advise. Question: Can a session-scoped bean be exposed as a MVC Controller argument There appears to be an annotation for this: @SessionAttributes("myBean") however this only maintains a Controller-level scope. I'm looking to avoid having to interact with HttpSession and instead pass around my domain object graph consistently through my

Passing data from View to Controller

痴心易碎 提交于 2019-12-10 20:44:02
问题 In an ASP.NET MVC application, I'm making logic for Admin to accept or reject new members. I'm showing a list of members and two buttons Accept and Reject, like this: <% foreach (var mm in (ViewData["pendingmembers"] as List<MyMember>)) %> <% { %> <tr><td>Username:<%=mm.UserName %></td><td> <tr><td>Firstname:<%=mm.FirstName %></td><td> ...etc... <tr> <td> <% using (Html.BeginForm("AcceptPendingUser", "Admin")) { %> <input type="submit" value="Accept" /> <% } %> </td> <td> <% using (Html

Should I call redirect() from within my Controller or Model in an MVC framework?

為{幸葍}努か 提交于 2019-12-10 20:23:35
问题 I'm using the MVC PHP framework Codeigniter and I have a straight forward question about where to call redirect() from: Controller or Model? Scenario: A user navigates to www.example.com/item/555. In my Model I search the item database for an item with the ID of 555. If I find the item, I'll return the result to my controller. However, if an item is not found, I want to redirect the user somewhere. Should this call to redirect() come from inside the model or the controller? Why? 回答1: No your

Laravel Controller get limit number item

ぃ、小莉子 提交于 2019-12-10 19:18:28
问题 In my Controller $items = Item::all(); I want to get the first 6 items only How to change the code? 回答1: Use take() method: $items = Item::take(6)->get(); 回答2: Use take function $items = Item::take(6)->get(); Check in laravel docs : https://laravel.com/docs/5.2/queries 回答3: To limit the number of results returned from the query you may use the take() method. $items = Item::take(6)->get(); 回答4: or this $items = Item::paginate(6); 来源: https://stackoverflow.com/questions/38930388/laravel

Ignore URI(request.referer).path for previous URL when visiting directly to a page

放肆的年华 提交于 2019-12-10 18:54:06
问题 I'm trying to save the previous URL in a session, I currently have this code: after_filter "save_my_previous_url", only: [:renderForm, :renderQuote] def save_my_previous_url if URI(request.referer).path session[:my_previouse_url] = URI(request.referer).path else session[:my_previouse_url] = URI(request.referer).path end end It works when you go from a page, to the form, then to the thank you page, but if you go straight to a form directly instead of clicking a link, I get this error: bad

Push/Present Modal View Controller

可紊 提交于 2019-12-10 18:54:00
问题 I have a table in my view controller (let's call it TVC1). I have rows in TVC1 that are used so the user can input some more data in addition to the data on TVC1. So, when someone taps a specific row in TVC1, it will show another view controller (let's call it TVC2). However, when TVC2 is shown, all of the data in TVC1 is cleared. How can I save the data in TVC1? Should I do it through the app delegate? DescriptionInputViewController *descriptionController = [[DescriptionInputViewController