我的控制器中有以下数据:
$scope.breeds = ["Poodle", "Collie", "German shepherd"];
$scope.dogs = [
{ name: "Bingo", breed: "Poodle" },
{ name: "Lassie", breed: "Collie" },
{ name: "Bert", breed: "German shepherd" },
{ name: "Lily", breed: "Poodle" },
{ name: "Obi-Wan", breed: "Collie" }
];
Run Code Online (Sandbox Code Playgroud)
这是我的HTML:
<select ng-model="query.breed" ng-options="breed for breed in breeds">
<option value="">All breeds</option>
</select>
<table>
<thead>
<tr>
<th>Name</th>
<th>Breed</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="dog in dogs |filter:query">
<td>{{dog.name}}</td>
<td>{{dog.breed}}</td>
</tr>
</tbody>
</table>
Run Code Online (Sandbox Code Playgroud)
一切正常 - 当我选择Collie时,会显示品种为=="Collie"的物品,等等.但我无法弄清楚如何使"所有品种"选项有效.
我已经创建了一个ASP.Net API控制器,我正在尝试使用Angular发出POST请求.请求到达我的控制器方法,但参数值为null.
我的角色代码:
$http({ method: 'POST', url: '/api/Contents', data: "value=foobar", headers: { 'Content-Type': 'application/x-www-form-urlencoded' } }).
success(function(data) {
}).
error(function(data, status, headers, config) {
});
Run Code Online (Sandbox Code Playgroud)
我也试过json(Json是我最想要的):
$http({ method: 'POST', url: '/api/Contents', data: { "foo": "bar", "foo2": "bar2" }, headers: { 'Content-Type': 'application/json'} }).
success(function(data) {
}).
error(function(data, status, headers, config) {
});
Run Code Online (Sandbox Code Playgroud)
我的(非常简单)Controller方法如下所示:
public void Post([FromBody]string value)
{
//But Value is NULL!!!!!!
}
Run Code Online (Sandbox Code Playgroud)
以下是我从Chrome中删除的请求标题中的一些值(我认为可能很有趣:
我错过了什么?