我有作用的結果,它發送的內容一樣呈現在成功阿賈克斯警報HTML下面如何使用asp.net的MVC和jQuery
public ActionResult MyAction()
{
string mystring = //doing some thing
return Content(mystring , "html");
}
客戶端
$.ajax({
url: "/MyController/MyAction",
type: "POST",
dataType: "html",
data: details,
success: function (response) {
if (response != "") {
alert(response);
}
}
});
我現在的字符串或我發送的迴應是(它可以是更多的數字,如1,2,3動態)
"\\n 1: blah blah.\\n 2: blah blah"
,並在警告其未來作爲
\n 1: blah blah.\n 2: blah blah
如何使警覺的樣子
1.blah blah.
2.blah blah.
不能改變在服務器端的東西,改變只允許在客戶端
的可能的複製[爲什麼在這個JavaScript警告窗口工作不換行?(http://stackoverflow.com/questions/8967722/why-are-new-lines-not-working-in- this-javascript-alert-window) – George
'return Content(mystring,「html」);'應該是'return Content(mystring,「text/plain」);'問題出在服務器端,不發送你發送的新行「\ n」 – George