IndieTech Solutions
IndieTech Solutions

Reputation: 2539

Calling different actions from the same controller/view

Here's the scenario: I am working on a file/folder management system. when i want to create a new folder i want to create it in the server and also in the dropBox (using an API). The way my code is organized right now is that i have two controllers, one for the folders "Folder" and one for DropBox interactions "DropBox"

Using the return RedirectToAction() works for me but i dont think it's the best way to do it.

here's the order of my calls: - From the Folder view i call create_folder in the "Folder" controller. - After doing all the processing in the "Folder" controller I redirect to the "DropBox" controller using return RedirectToAction("create_Folder","DropBox") - After doing all the processing in the "DropBox" controller i redirect back to the "Folder" index view to display the created folder.

I don't think it's the best way to do it. i think it's a routing concept that i am not really understanding here. When i tried to add a new action in the folder controller (I called it Create_Folder_complete) and included Create_Folder() and then call Create_Folder_DRopBox() i got a reference null error message.

what am i missing here? i want to make my code as clean as possible and follow the MVC best practices.

Upvotes: 0

Views: 556

Answers (2)

Matt M
Matt M

Reputation: 3779

Why not create a service that can handle the processing that you do in the folder controller function AND the dropbox controller function. You can call this service method from your folder controller and then redirect to the index action of the folder controller when it's complete.

Upvotes: 1

Chris Pratt
Chris Pratt

Reputation: 239460

You shouldn't have separate actions for each task. The action is responsible for creating the "folder". The fact that it's also interacting with DropDox to create a folder there is an implementation detail that shouldn't be exposed to the enduser. Do all the work directly in one action that responds to the submission of your create folder form, and then either redirect to a success page or return the view on error.

Upvotes: 2

Related Questions