C# 从ajax调用控制器时,从asp.net MVC中的控制器逐个打印值

C# 从ajax调用控制器时,从asp.net MVC中的控制器逐个打印值,c#,asp.net-mvc,C#,Asp.net Mvc,我对controller有一个AJAX调用,如下所示 function print(response, endpoint) { $(".tt").append("<tr><td>" + JSON.stringify(response[0], null) + "</td><td>" + JSON.stringify(response[1], null) + "</td><td>" + JSON.stringif

我对controller有一个AJAX调用,如下所示

function print(response, endpoint) {
        $(".tt").append("<tr><td>" + JSON.stringify(response[0], null) + "</td><td>" + JSON.stringify(response[1], null) + "</td><td>" + JSON.stringify(response[2], null) + "</td><td>" + JSON.stringify(response[3], null) + "</td><td>" + JSON.stringify(endpoint, null) + "</td></tr>");
    } 

   $(".submit").click(function () {
            var env = $("#env").find(":selected").text();
            var region = $("#region").find(":selected").text();
            var country = $("#country").find(":selected").text()
            var folderPath = $.trim($('#folderPath').val());



                var ajaxRequest = $.ajax({
                    contentType: "application/json ;charset=utf-8",
                    type: "GET",
                    async: false,
                    url: "/Home/GetmyModel" + "?selcetion=" + env + "&region=" + region + "&country=" + country + "&folderpath=" + folderPath,
                    success: function (response) {
                        if (response != null) {
                            //print(response, endpoints[i]);
                        }
                    },
                    error: function (exception) {
                    },
                    complete: function (data) {
                    }
                });
函数打印(响应、端点){
$(“.tt”).append(“+JSON.stringify(response[0],null)+”“+JSON.stringify(response[1],null)+”“+JSON.stringify(response[2],null)+”“+JSON.stringify(response[3],null)+”“+JSON.stringify(endpoint,null)+”);
} 
$(“.submit”)。单击(函数(){
var env=$(“#env”).find(“:selected”).text();
var region=$(“#region”).find(“:selected”).text();
var country=$(“#country”).find(“:selected”).text()
var folderPath=$.trim($('#folderPath').val());
var ajaxRequest=$.ajax({
contentType:“应用程序/json;字符集=utf-8”,
键入:“获取”,
async:false,
url:“/Home/GetmyModel”+”?选择=“+env+”®ion=“+region+”&country=“+country+”&folderpath=“+folderpath,
成功:功能(响应){
if(响应!=null){
//打印(响应,端点[i]);
}
},
错误:函数(异常){
},
完成:功能(数据){
}
});
我的控制器是这样的

public void GetmyModel(string selcetion, string region, string country, string folderpath)
        {

foreach (var item in System.IO.File.ReadLines(folderpath))
            {
//do some work with return value as list<string>
//show list<string> in table in view using either print method of JS or by another way 
}

}
public void GetmyModel(字符串选择、字符串区域、字符串国家/地区、字符串文件夹路径)
{
foreach(System.IO.File.ReadLines(folderpath)中的变量项)
{
//使用返回值作为列表执行一些操作
//使用JS的打印方法或其他方式在视图中的表中显示列表
}
}

如果我通过将返回类型设置为
JsonResult
来发送完整的响应,则一切正常。但是,我不知道如何打印每个项目。

您期望的输出是什么?我想在表中写入字符串类型的输出,就像在打印javascript函数中一样。不清楚您要求的内容。您的方法应该返回一个集合(作为
JsonResult
,然后循环遍历集合中的每个项目(使用
$.each()
for
循环)要在对项执行某些操作后生成元素,我要在UI上显示的结果控制器方法中的代码是否生成一个
列表
,是否要对集合中的每个项生成一个
,并将其输出到表单元格?