简体   繁体   English

值不会从一个控制器传递到另一个控制器

[英]Values aren't being passed from one controller to another controller

Passing data between two separate controllers. 在两个单独的控制器之间传递数据。 I have the following in my first file: 我的第一个文件中包含以下内容:

public ActionResult Report(string sDate, string eDate)
{   
    var client = new WebClient();
    string avgRatesCos = String.Format(client.DownloadString("http://localhost/api/values/1?sBookingDate={0}&eBookingDate={1}"), sDate, eDate);
    string maxAvgRates = String.Format(client.DownloadString("http://localhost/api/values/2?sBookingDate={0}&eBookingDate={1}"), sDate, eDate);
    string minAvgRates = String.Format(client.DownloadString("http://localhost/api/values/3?sBookingDate={0}&eBookingDate={1}"), sDate, eDate);

in my second file/controller my values in 'sBookingDate' and 'eBookingDate' show up as {0} and {1} instead of values being passed from the first controller: 在我的第二个文件/控制器中,我在'sBookingDate'和'eBookingDate'中的值显示为{0}和{1},而不是从第一个控制器传递的值:

public QueryResponse Get(int id, string sBookingDate, string eBookingDate)
{
    Console.WriteLine(sBookingDate, eBookingDate);
}

You've got your String.Format and your client.DownloadString operations backwards. 您已经有了String.Formatclient.DownloadString操作向后。 So you're literally just requesting the {0} as the parameter... then calling String.Format on the result of the call to the action/controller. 因此,您实际上只是在请求{0}作为参数...然后在对操作/控制器的调用结果上调用String.Format

Instead of 代替

string avgRatesCos = String.Format(client.DownloadString("http://localhost/api/values/1?sBookingDate={0}&eBookingDate={1}"), sDate, eDate);

it should be 它应该是

string avgRatesCos = client.DownloadString(String.Format("http://localhost/api/values/1?sBookingDate={0}&eBookingDate={1}", sDate, eDate));

尝试

string minAvgRates = client.DownloadString("http://localhost/api/values/3?sBookingDate=" +sDate + "&eBookingDate="+eDate);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM