我有一个webform页面,调用webapi方法来保存一些数据.我正在使用HttpClient进行调用并执行webapi.
我尝试使用webAPI压缩将巨大的xml发布到API.我基本上使用这两个网站作为参考:http: //www.ronaldrosier.net/blog/2013/07/16/implement_compression_in_aspnet_web_api和http://benfoster.io/blog/aspnet-web-api-compression
API正在运行,它正确地触发处理程序.我在服务器端的webforms上尝试压缩和发布对象时遇到了一些问题.
这是我试过的代码:
bool Error = false;
//Object to post. Just an example...
PostParam testParam = new PostParam()
{
inputXML = "<xml>HUGE XML</xml>",
ID = 123
};
try
{
using (var client = new HttpClient())
{
using (var memStream = new MemoryStream())
{
var data = new DataContractJsonSerializer(typeof(PostParam));
data.WriteObject(memStream, testParam);
memStream.Position = 0;
var contentToPost = new StreamContent(this.Compress(memStream));
contentToPost.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");
contentToPost.Headers.Add("Content-Encoding", "gzip");
var response = client.PostAsync(new Uri("http://myapi/SAVE"), contentToPost).Result;
var dataReceived = response.EnsureSuccessStatusCode(); …Run Code Online (Sandbox Code Playgroud) 我刚刚开始使用Angular 4,我需要开发一个CRUD网格,用户可以在其中添加,编辑或删除行.
在我的研究过程中,我发现这篇文章展示了如何创建网格以及动作:带有CRUD操作的Angular 4 Grid.
看看他的代码,引起我注意的是他使用ng-template在编辑/查看模式之间切换的方式.
<tr *ngFor="let emp of EMPLOYEES;let i=idx">
<ng-template [ngTemplateOutlet]="loadTemplate(emp)" [ngOutletContext]="{ $implicit: emp, idx: i }"></ng-template>
</tr>
Run Code Online (Sandbox Code Playgroud)
在文章中,他使用模板驱动的表单来编辑行.但是,我试图改变为反应形式.
在我尝试这样做时,我试图将[(ngModel)]替换为formControlName,我遇到了一些错误.我的第一次尝试,我试图在表单元素的模板html开头添加[formGroup].但是当我尝试运行并编辑该行时,出现以下错误:
Error: formControlName must be used with a parent formGroup directive. You'll want to add a formGroup directive and pass it an existing FormGroup instance (you can create one in your class).
Run Code Online (Sandbox Code Playgroud)
当我尝试在ng-template中移动[formGroup]时,它可以工作,但是我无法将值绑定到字段,我不得不在loadTemplate函数中设置值:
loadTemplate(emp: Employee) {
if (this.selemp && this.selemp.id === emp.id) {
this.rForm.setValue({
id: emp.id,
name: emp.name
});
return this.editTemplate;
} else {
return this.readOnlyTemplate; …Run Code Online (Sandbox Code Playgroud) 有人可以帮我弄清楚最好的方法是怎样做的?
我有车的人员名单.我需要执行一个查询,该查询将返回具有某种类型的汽车且同时没有其他类型的人.
这是我的例子:
ID Name CarType
----------- ---------- ----------
1 John MINI VAN
1 John SUV
2 Mary SUV
2 Mary SEDAN
3 Paul SPORT
3 Paul TRUCK
4 Joe SUV
4 Joe MINI VAN
Run Code Online (Sandbox Code Playgroud)
例如,我想只显示有SUV且没有MINI VAN的人.如果我们尝试子句CarType IN('SUV')而不是IN('MINI VAN'),这将不起作用,因为第二个语句被忽略.
为了返回具有类型但同时没有其他类型的人,我尝试了以下方法:
我正在使用的查询是这样的:
--This is the IN Clause
declare @Contains table(
ID int not null
)
--This is the NOT IN Clause
declare @DoesNotContains table(
ID int not null
)
--Select IN
insert into @Contains
SELECT ID …Run Code Online (Sandbox Code Playgroud)