我正在尝试在新窗口页面中返回View,但我总是收到内部500错误...问题出在控制器中,但我似乎没有找到解决问题的方法..
JavaScript
//other codes
{
url: 'Index/Booklist',
method: 'POST',
success: function(a) {
window.open(Index/Booklist);
},
fail: function(a)
// other codes
}
控制器
[HttpPost]
public ActionResult Booklist() {
ViewData["test"] = "some value"
return View();
// I want to send data from Controller to View but it keeps giving an internal 500 error
}
查看
<head>
//added <script></script>
</head>
<body>
<p> to receive data from controller </p> @ViewData["test"]
</body>
答案 0 :(得分:0)
的JavaScript
//other codes
{
url: 'Index/Booklist',
method: 'POST',
success: function(a) {
window.open(Index/Booklist);
},
fail: function(a)
// other codes
}
控制器
public ActionResult Booklist() {
ViewData["test"] = "some value"
return Content("success"); // changed here
}
查看
<head>
//added <script></script>
</head>
<body>
<p> to receive data from controller </p> @ViewData["test"]
</body>
基本上我改变了View();内容(&#34;成功&#34;)。 (如上所示)
但我发现你可以使用View();也如下所示。 它是删除POST方法和url(错误原因)
的JavaScript
//other codes
{
// all the other codes were removed POST method and url which is causing the error
window.open(Index/Booklist);
}
控制器
public ActionResult Booklist() {
ViewData["test"] = "some value"
return View();
}
查看
<head>
//added <script></script>
</head>
<body>
<p> to receive data from controller </p> @ViewData["test"]
</body>