如何将 ac# 对象返回到 javascript (mvc2)
我正在 MVC2 中实现图像上传。我已经用uplpadify实现了imageupload:
<script type="text/javascript">
$('#FileInput').uploadify({
'uploader': '../../../../Scripts/swf/uploadify.swf',
'script': '/Market/RR/BildUpload',
'cancelImg': '../../../../Content/images/cancel.png',
'folder': '//Uploades/RR/',
'auto': true,
'sizeLimit': 102400,
'removeCompleted': false,
'fileExt': '*.jpg;*.gif;*.png',
'fileDesc': 'Image Files',
'multi': true,
'onComplete': function (event, queueID, fileObj, response, data) {
var fname = response;
}
});
</script>
控制器保存图像:
public Bilder BildUpload()
{
Bilder b = new Bilder();
if (Request.Files.Count > 0)
{
file.SaveAs(Server.MapPath(@"\Uploads\Horses\images\full\") + id + f.Extension);
b.Pfad = host + id + f.Extension;
b.ID_Bild = Convert.ToInt16(id);
return b;
}
else
{
return b;
}
}
但是如何获取我返回的对象Bild的值?我尝试过类似 result.Pfad
但这不起作用。 您对如何解决这个问题有什么想法吗? 谢谢!!!
I'm realizing an imageupload in MVC2. I've realized the imageupload with uplpadify:
<script type="text/javascript">
$('#FileInput').uploadify({
'uploader': '../../../../Scripts/swf/uploadify.swf',
'script': '/Market/RR/BildUpload',
'cancelImg': '../../../../Content/images/cancel.png',
'folder': '//Uploades/RR/',
'auto': true,
'sizeLimit': 102400,
'removeCompleted': false,
'fileExt': '*.jpg;*.gif;*.png',
'fileDesc': 'Image Files',
'multi': true,
'onComplete': function (event, queueID, fileObj, response, data) {
var fname = response;
}
});
</script>
The controler saves the image:
public Bilder BildUpload()
{
Bilder b = new Bilder();
if (Request.Files.Count > 0)
{
file.SaveAs(Server.MapPath(@"\Uploads\Horses\images\full\") + id + f.Extension);
b.Pfad = host + id + f.Extension;
b.ID_Bild = Convert.ToInt16(id);
return b;
}
else
{
return b;
}
}
But how to get the value of my returned object Bild? I have tried things like result.Pfad
But it does not work.
Do you have any ideas how to solve this problem?
Thanks!!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过返回 JSONResult() 或 Content(),并传入要返回给 ajax 调用者的文件名值?
Have you tried returning a JSONResult() or a Content(), passing in the value of the file name you want to return back to the ajax caller?