How to call another controller Action From a controller in Mvc

As @mxmissile says in the comments to the accepted answer, you shouldn’t new up the controller because it will be missing dependencies set up for IoC and won’t have the HttpContext. Instead, you should get an instance of your controller like this: var controller = DependencyResolver.Current.GetService<ControllerB>(); controller.ControllerContext = new ControllerContext(this.Request.RequestContext, controller);

Access Controller method from another controller in Laravel 5

You can access your controller method like this: app(‘App\Http\Controllers\PrintReportController’)->getPrintReport(); This will work, but it’s bad in terms of code organisation (remember to use the right namespace for your PrintReportController) You can extend the PrintReportController so SubmitPerformanceController will inherit that method class SubmitPerformanceController extends PrintReportController { // …. } But this will also inherit all other … Read more

Can we pass model as a parameter in RedirectToAction?

Using TempData Represents a set of data that persists only from one request to the next [HttpPost] public ActionResult FillStudent(Student student1) { TempData[“student”]= new Student(); return RedirectToAction(“GetStudent”,”Student”); } [HttpGet] public ActionResult GetStudent(Student passedStd) { Student std=(Student)TempData[“student”]; return View(); } Alternative way Pass the data using Query string return RedirectToAction(“GetStudent”,”Student”, new {Name=”John”, Class=”clsz”}); This will generate … Read more

How to create separate AngularJS controller files?

File one: angular.module(‘myApp.controllers’, []); File two: angular.module(‘myApp.controllers’).controller(‘Ctrl1’, [‘$scope’, ‘$http’, function($scope, $http){ }]); File three: angular.module(‘myApp.controllers’).controller(‘Ctrl2’, [‘$scope’, ‘$http’, function($scope, $http){ }]); Include in that order. I recommend 3 files so the module declaration is on its own. As for folder structure there are many many many opinions on the subject, but these two are pretty good … Read more

How do I create a simple ‘Hello World’ module in Magento?

First and foremost, I highly recommend you buy the PDF/E-Book from PHP Architect. It’s US$20, but is the only straightforward “Here’s how Magento works” resource I’ve been able to find. I’ve also started writing Magento tutorials at my own website. Second, if you have a choice, and aren’t an experienced programmer or don’t have access … Read more

Can an ASP.NET MVC controller return an Image?

Use the base controllers File method. public ActionResult Image(string id) { var dir = Server.MapPath(“/Images”); var path = Path.Combine(dir, id + “.jpg”); //validate the path for security or use other means to generate the path. return base.File(path, “image/jpeg”); } As a note, this seems to be fairly efficient. I did a test where I requested … Read more