ASP MVC 如何将内存中的字节流传递给Java Applet?
我需要将图像(当前是字节流)传递到 ASP MVC 3.0 网站中的 Java Applet。
该小程序的文档表示该文件可以通过 HTTP GET 动态生成。
获取动态内容的控制器操作应该返回什么?
另外,如何在小程序的 Html 中指定 Url?
我尝试从控制器返回文件结果,并在文件名应该去的地方嵌入“Html.RenderAction”调用,但我收到此错误(在下面包含的 Html 片段上)
CS1502: 最佳重载方法匹配 'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)' 有一些无效参数
HTML 片段
<param name="Filename" value="@Html.RenderAction("DownLoadImage", "Document", new { DocumentId = Model.DocumentId, Page = Model.Page })">
控制器操作
public ActionResult DownloadImage(string DocumentId, int PageNo)
{
byte[] bytes = documentProvider.GetImage(DocumentId, PageNo);
return File(bytes, "image/tiff");
}
当我在“下载图像”ActionLink 中使用 DownloadImage
操作时,它会起作用。
如果您还需要什么,请告诉我。
如果我做了一些愚蠢的事情,或者错过了一些非常明显的事情,请道歉。我对Web开发知之甚少,这是我的第一个ASP MVC应用程序,也是我第一次使用Java Applet。 。 。 请温柔一点
谢谢。
I need to pass an image (currently a byte stream) to a Java Applet in an ASP MVC 3.0 web site.
The docs for the applet says the file can be generated dynamically by a HTTP GET.
What should the Controller action that gets the dynamic content return?
Also, how do I specify the Url in the Html for the applet?
I've tried returning a File result from the controller, and embedding a "Html.RenderAction" call where the file name should go, but I get this error (on the Html fragment included below)
CS1502: The best overloaded method match for
'System.Web.WebPages.WebPageExecutingBase.Write(System.Web.WebPages.HelperResult)'
has some invalid arguments
HTML fragment
<param name="Filename" value="@Html.RenderAction("DownLoadImage", "Document", new { DocumentId = Model.DocumentId, Page = Model.Page })">
Controller Action
public ActionResult DownloadImage(string DocumentId, int PageNo)
{
byte[] bytes = documentProvider.GetImage(DocumentId, PageNo);
return File(bytes, "image/tiff");
}
The DownloadImage
action works when I use it in a "download image" ActionLink.
Please let me know if you need anything else.
Apologies if I'm doing something dumb, or missing something very obvious. I know very little about Web Development, this is my first ASP MVC application, and the first time I've used a Java Applet . . . please be gentle
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
synatx 错误来自 Razor——它的渲染方式与 Writer 使用的旧 WebForms 视图模型不同。但这有点转移注意力——实际上您无论如何都不想这样做——这是试图删除正在流式传输到 HTML 中的图像数据字节。
我认为您想要做的是将小程序传递一个 URL 到渲染图像的控制器操作。它会从电线上读取它,然后做它的事情。您的代码可能应该如下所示:
没有与小程序的座位时间,所以我不确定这是否可以解决问题。您可能需要将其设置为绝对 URI,或者您可能会在身份验证方面遇到一些挑战,具体取决于底层的工作方式。
The synatx error is from Razor -- it renders differently than the old WebForms viewmodels which is used the Writer. But that is a bit of a red herring here -- you actually don't want to do it this way anyhow -- this is trying to drop the bytes of image data you are streaming into the HTML.
What I think you want to do is pass the applet a URL to the controller action that is rendering the image. It will read it off the wire then do it's thing. Your code should probably look like:
Have no seat time with the applet so I'm not sure if that will do the trick. You might need to make it an absolute URI, or you might have some challenges with authentication depending on how things work under the hood.