我从AngularJS调用C#操作方法(Mvc.Controller),并且该操作中的param为null。为什么呢?
以下是Angular电话:
return $http.get(
"AdvancedSearch/SearchUsers",
{
params: {
search: {
SearchTerms: searchTerms,
Markets: markets,
Roles: roles,
Capabilities: capabilities,
Groups: groups,
Industries: experience,
Skills: skills,
Technologies: technologies,
Certifications: certification
}
}
}
);
这是C#视图模型:
public class SearchViewModel
{
public string SearchTerms { get; set; }
public List<string> Markets { get; set; }
public List<int> Roles { get; set; }
public List<string> Capabilities { get; set; }
public List<string> Groups { get; set; }
public List<int> Industries { get; set; }
public List<int> Skills { get; set; }
public List<int> Technologies { get; set; }
public List<string> Certifications { get; set; }
}
这里是行动方法签名:
[HttpGet]
public JsonResult SearchUsers(SearchViewModel search) // <- this is null
这是请求网址,已解码:
https://localhost:44300/AdvancedSearch/SearchUsers?search={"SearchTerms":"","Markets":["Boise"],"Roles":[],"Capabilities":[],"Groups":[],"Industries":[],"Skills":[],"Technologies":[],"Certifications":[]}
在我使用单独的参数转换为使用单一视图模型之前,调用工作正常。
更新:尝试传递为单个字符串参数。
以下是Angular电话:
return $http.get(
"AdvancedSearch/SearchUsers",
{
params: JSON.stringify({
jsonSearchData: {
SearchTerms: searchTerms,
Markets: markets,
Roles: roles,
Capabilities: capabilities,
Groups: groups,
Industries: experience,
Skills: skills,
Technologies: technologies,
Certifications: certifications
}
})
}
);
这是新的C#方法签名:
public JsonResult SearchUsers(string jsonSearchData) // still coming over null
答案 0 :(得分:0)
试试这个
[1, "2"]