从.net中的另一个应用程序调用asp mvc Controller Action? [英] Call asp mvc Controller Action from another application in .net?

查看:144
本文介绍了从.net中的另一个应用程序调用asp mvc Controller Action?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从控制台应用程序中运行引用我的MVC应用程序的控制器动作。

I need to run a Controller Action from my Console Application that reference to my MVC App.

其背后的原因是因为有一些特殊的Action方法,我不能简单地将其复制到新的应用程序中。 (由于控制的原因)

The reason behind this is because there are some special Action method that i cannot just simply copy to the new application. (Because of the control things)

所以我只想问问是否可以通过控制台应用程序调用控制器操作方法?如何将文件上传发送到控制器?

So I just want to ask if there could be any way to call a controller action method from the Console application? How could I send a file upload to the controller?

这是我用来上传文件的ActionResult示例?我应该如何向其中发送Request.Files?

This is the example of my ActionResult that used to upload a file? how should i send the Request.Files to it?

  public ActionResult ImageUp(){
        foreach (string fname in Request.Files)
        {
            HttpPostedFileBase _file = Request.Files[fname];
        }
  }


推荐答案

I确实可以,但是要正确插入所有内容需要花费一些工作。您可以创建控制器类的实例,然后从该实例调用ImageUp方法。为了正确设置Request.Files,您需要创建自己的ControllerContext实例,以便将所需的值压入Request.Files。

I am pretty sure you can but it will take a bit of work to plug everything in correctly. You can create an instance of the controller class and call the ImageUp method from that instance. To setup the Request.Files correctly you will need to create your own instance of ControllerContext in order to push the values you want into Request.Files.

这篇关于从.net中的另一个应用程序调用asp mvc Controller Action?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆