P.B*_*key 5 c# jquery asp.net-mvc-3
我已经看到了如何在JSON中序列化到一个对象.如何POST一个返回的字符串ViewResult?
$.ajax({
url: url,
dataType: 'html',
data: $(this).val(), //$(this) is an html textarea
type: 'POST',
success: function (data) {
$("#report").html(data);
},
error: function (data) {
$("#report").html('An Error occured. Invalid characters include \'<\'. Error: ' + data);
}
});
Run Code Online (Sandbox Code Playgroud)
MVC
[HttpPost]
public ActionResult SomeReport(string input)
{
var model = new ReportBL();
var report = model.Process(input);
return View(report);
}
Run Code Online (Sandbox Code Playgroud)
怎么样:
$.ajax({
url: url,
dataType: 'html',
data: {input: $(this).val()}, //$(this) is an html textarea
type: 'POST',
success: function (data) {
$("#report").html(data);
},
error: function (data) {
$("#report").html('An Error occured. Invalid characters include \'<\'. Error: ' + data);
}
});
Run Code Online (Sandbox Code Playgroud)
如果data使用与参数名称匹配的键创建一个JSON对象,MVC应该选择它.
在MVC方面......
[HttpPost]
public ActionResult SomeReport()
{
string input = Request["input"];
var model = new ReportBL();
var report = model.Process(input);
return View(report);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4849 次 |
| 最近记录: |