Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

asp.net call controller from another controller

public class HomeController : Controller
{
    private Areas.Api.Controllers.FoobarController _foobarController;
    public HomeController(Areas.Api.Controllers.FoobarController foobarController)
    {
        _foobarController = foobarController;
    }

    private void InitControllers()
    {
        // We can't set this at Ctor because we don't have our local copy yet
        // Access to Url 
        _foobarController.Url = Url;
        // Access to User
        _foobarController.ActionContext = ActionContext;
        // For more references see https://github.com/aspnet/Mvc/blob/6.0.0-rc1/src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs
        // Note: This will change in RC2
    }

    public IActionResult Index()
    {
        InitControllers();

        var model = new IndexViewModel();
        model.Foo = _foobarController.List(new FoobarRequest() { Foo = true, Bar = false });
        model.Bar = _foobarController.List(new FoobarRequest() { Foo = false, Bar = true });
        return View(model);
    }
}
Comment

PREVIOUS NEXT
Code Example
Csharp :: static constructor in c# 
Csharp :: HtmlToPdfConverter 
Csharp :: if statement in razor using "?" and ":" 
Csharp :: enum in combobox wpf 
Csharp :: ##[error]Dotnet command failed with non-zero exit code on the following projects 
Csharp :: c# get all occurrences of a string 
Csharp :: play sound in sequence unity 
Csharp :: display image script unity 
Csharp :: c# bool list count true 
Csharp :: trygetvalue c# 
Csharp :: c# sbyte 
Csharp :: remove all values from list c# 
Csharp :: winforms combobox get selected text 
Csharp :: list to ilist c# 
Csharp :: serialize object to json 
Csharp :: crud operation in asp.net 
Csharp :: datetime show 24 hour format c# 
Csharp :: asp.net web forms 
Csharp :: string.format() c# 
Csharp :: unity trygetcomponent 
Csharp :: create app() import vue cli 
Csharp :: how to instantiate more enemies in unity 
Csharp :: 1180 beecrowd URI 
Csharp :: c# on alt + f4 
Csharp :: optional parameter get request c# 
Csharp :: Photon Register Callbacks 
Csharp :: C# decimal built-in methods 
Csharp :: copy file image in c# 
Csharp :: make first 2 words upper case c# 
Csharp :: générer un nombre aléatoire en c# 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =