假设我在我的客户端模型中有一个数组:
vm.dataSheets = [
{ value: 0, text: localize.getLocalizedString('_ProductsAndServices_'), selected: selected},
{ value: 1, text: localize.getLocalizedString('_Holidays_'), selected: selected },
{ value: 2, text: localize.getLocalizedString('_Locations_'), selected: selected },
{ value: 3, text: localize.getLocalizedString('_OpHours_'), selected: selected },
{ value: 4, text: localize.getLocalizedString('_Users_'), selected: selected }
];我将其绑定到HTML上的复选框列表中。我想把那些被检查的值发送到web。使用angularJS,我可以过滤选定的对象如下:
$filter('filter')(vm.dataSheets, { selected: true })这将返回整个对象的数组。是否有一种简单的方法来检索选定的值,如1、2、3等.?
现在,我将数据发送到Web,如下所示:
var fd = new FormData();
fd.append('file', file);
fd.append('clientId', $rootScope.appData.clientId);
fd.append('sheets', $filter('filter')(vm.dataSheets, { selected: true }));
$http.post("TIUSP/systemengine/ClientSupply", fd, {
withCredentials: true,
headers: {'Content-Type': undefined },
transformRequest: angular.identity
}).success(function () {
}在web中,如何检索选定的值?当我用
HttpContext.Current.Request["sheets"];它给了我一个字符串作为对象、对象等.
发布于 2016-06-06 15:07:25
若要将选定的值作为带有Ids的数组返回,可以创建自定义筛选器:
app.filter('selected', function() {
return function(items) {
var filtered = [];
for (var i = 0; i < items.length; i++) {
var item = items[i];
if (item.selected === true) {
filtered.push(item.id);
}
}
return filtered;
};
});然后,使用它:
var fd = {
'file': file,
'clientId': $rootScope.appData.clientId,
'sheets': $filter('selected')(foo.results)
};
$http.post("TIUSP/systemengine/ClientSupply", fd, {
withCredentials: true,
headers: {'Content-Type': undefined },
transformRequest: angular.identity
}).success(function () {
}这将创建如下内容:
{
file: 'path-to-my-filez/image.png',
clientId: 11,
sheets: [1,2,3,4]
}Web控制器中的
创建一个类,该类映射在请求中发送的参数:
public class ClientSupplyViewModel
{
public string file {get; set;}
public int clientId [get; set;}
public int[] sheets {get; set;}
}然后,在控制器中使用它:
[HttpPost]
public HttpResponseMessage ClientSupply(ClientSupplyViewModel data)
{
}上面的控制器只是一个例子。唯一重要的部分是包含您的文件、ClientId和ints数组的数据参数。
https://stackoverflow.com/questions/37658041
复制相似问题