如何从MVC控制器获取值并将其传递给控制台应用程序 [英] How to get the values from the MVC controller and pass it to console application

查看:277
本文介绍了如何从MVC控制器获取值并将其传递给控制台应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,

在我的项目中,我使用控制台应用程序来执行后台作业,因为我无法从MVC控制器获取值并将值传递给控制台应用程序。 MVC的新手不知道如何将值从控制器传递到控制台应用程序。请提出一些可以帮助我找到解决方案的解决方案。

解决方案

< pre lang =c#> class 计划{

static void Main( string [] args){

HttpClient client = new HttpClient();
var content = new StringContent( =这是我的输入字符串);
content.Headers.ContentType = new MediaTypeHeaderValue( 应用程序/ x WWW的形式进行了urlencoded);
client.PostAsync( http:// localhost:2451 / api / values, content)
.ContinueWith(task = > {

var response = task.Result;
Console.WriteLine(response.Content.ReadAsStringAsync()。Result);
});

Console.ReadLine();
}
}


Hi Friends,
In my project am using a console application to do a back job function in that am not able to get the value from MVC controller and pass the value to console application.As am new to MVC am not able to know how to pass the values from controller to console application.please suggest some solutions which may help me to get a solution.

解决方案

   class Program {

    static void Main(string[] args) {

        HttpClient client = new HttpClient();
        var content = new StringContent("=Here is my input string");
        content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
        client.PostAsync("http://localhost:2451/api/values", content)
            .ContinueWith(task => {

                var response = task.Result;
                Console.WriteLine(response.Content.ReadAsStringAsync().Result);
            });

        Console.ReadLine();
    }
}


这篇关于如何从MVC控制器获取值并将其传递给控制台应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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