如何在我的 c# api 中保留换行符?
How can I keep the break line in my c# api?
我在 html 中创建了一个 textarea
。在 textarea
你可以有换行。当我检查时,如果值 returns 断线,那很好。但是当我在 API
中这样做时
public string Put(string comment = "")
{
return comment ;
}
再看看我有没有断线,没有断线
这是我发送给 API
Test
test
这是 api
的回复
Testtest
有人知道我该如何解决我的问题?
更新
当我在 angularjs
中调用我的 api
$http.put('api/Test?comment=' + comment).then(function (response) {
console.log(response.data)
})
使用 console.log(response.data)
我看到我的 api 删除了换行符但是当我检查 console.log(comment)
我看到我的换行符。
更新
我猜这是绑定问题 String
,是否有其他绑定或解决方案可以解决我的问题?
通过自己构造查询字符串,您忽略了对参数进行编码。这不仅会导致换行问题,还会导致查询字符串中具有特殊含义的任何符号出现问题(例如 &
、+
)。它 你可以这样做:
$http.put('api/Test', {}, {params: {comment: comment}}).then(function (response) {
console.log(response.data)
});
您可能还想考虑在您的 put 正文而不是 URL 中传递注释。 (根据您的服务器端技术,您可能需要更改服务器端代码才能使其正常工作。)
$http.put('api/Test', {comment: comment}).then(function (response) {
console.log(response.data)
});
我在 html 中创建了一个 textarea
。在 textarea
你可以有换行。当我检查时,如果值 returns 断线,那很好。但是当我在 API
public string Put(string comment = "")
{
return comment ;
}
再看看我有没有断线,没有断线
这是我发送给 API
Test
test
这是 api
的回复Testtest
有人知道我该如何解决我的问题?
更新
当我在 angularjs
中调用我的 api$http.put('api/Test?comment=' + comment).then(function (response) {
console.log(response.data)
})
使用 console.log(response.data)
我看到我的 api 删除了换行符但是当我检查 console.log(comment)
我看到我的换行符。
更新
我猜这是绑定问题 String
,是否有其他绑定或解决方案可以解决我的问题?
通过自己构造查询字符串,您忽略了对参数进行编码。这不仅会导致换行问题,还会导致查询字符串中具有特殊含义的任何符号出现问题(例如 &
、+
)。它
$http.put('api/Test', {}, {params: {comment: comment}}).then(function (response) {
console.log(response.data)
});
您可能还想考虑在您的 put 正文而不是 URL 中传递注释。 (根据您的服务器端技术,您可能需要更改服务器端代码才能使其正常工作。)
$http.put('api/Test', {comment: comment}).then(function (response) {
console.log(response.data)
});