Pa1*_*Pa1 10 c# asp.net-mvc jquery kendo-ui
我正在使用Kendo UI上传控件.我已经定义了Kendo UI上传,如下所示:
<input type="file" name="resume" />
$("#file").kendoUpload({
async: {
saveUrl: "/Home/SaveResume",
autoUpload: true
},
complete: function (e)
{
// here i want to get the text that is returned from the controller
}
});
Run Code Online (Sandbox Code Playgroud)
控制器代码如下:
public ActionResult SaveResume(HttpPostedFileBase resume)
{
var text;
// code for the file to convert to text and assign it to text
return Json(text, JsonRequestBehavior.AllowGet);
}
Run Code Online (Sandbox Code Playgroud)
返回代码后,我想在完整的函数中检索代码.我怎样才能做到这一点?
Jon*_*han 10
您可以像这样获得对成功函数的响应
function onSuccess(e)
{
var response = e.response.data();
}
Run Code Online (Sandbox Code Playgroud)
返回json的地方
return Json(new { data = text }, "text/plain");
Run Code Online (Sandbox Code Playgroud)
如果你只是传回一个字符串,你应该能够做到:
function onSuccess(e) {
var text = e.XMLHttpRequest.responseText;
}
Run Code Online (Sandbox Code Playgroud)
如果需要,您还可以传回更复杂的对象:
// Object
public class MyObject
{
public int ID { get; set; }
public string Text { get; set; }
}
// Controller Action
public virtual ActionResult Upload(HttpPostedFileBase file)
{
return this.Json(new MyObject(), "text/plain");
}
// Javascript Handler
function onSuccess(e) {
var response = jQuery.parseJSON(e.XMLHttpRequest.responseText);
var id = response.ID;
var text = response.Text;
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
17038 次 |
最近记录: |