尝试使用 c# 7 元组,例如
public (string, bool) ProcessForm([FromBody]Dictionary<string,string> contactFormRequest)
但我收到错误“CS1031:预期类型”。我想这还不支持。
然后我尝试了
public Tuple<string, bool> ProcessForm([FromBody]Dictionary<string,string> contactFormRequest)
{
var message = "test";
var result = true;
var tuple = new Tuple<string, bool>(message, result);
return tuple;
}
这没有给出错误,但是我无法在 View 文件中拾取它
function handleResult(data) {
$("#custommessages").html(data.Item1);
}
$2sxc(@Dnn.Module.ModuleID).webApi.post("Form/ProcessForm", {}, newItem, true).then(handleResult);
这不会输出任何内容。
如果我从 Controller 返回一个简单的字符串,“数据”会很好地选择它。
如何从元组返回中获取值?
最佳答案
为什么不创建一个 POCO 类进行序列化:
public class SomeResult
{
public string Message{get;set;}
public bool Result{get;set;}
}
然后
public SomeResult ProcessForm([FromBody]Dictionary<string,string> contactFormRequest)
{
var message = "test";
var result = true;
return new SomeResult{Message = message, Result = result};
}
关于javascript - 将Tuple返回给 View 中的js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52609304/