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 Devel开发者_开发技巧opment, this is my first ASP MVC application, and the first time I've used a Java Applet . . . please be gentle
Thanks.
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:
<param name="Filename" value="@Url.Action("DownLoadImage", "Document", new { DocumentId = Model.DocumentId, Page = Model.Page })">
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.
精彩评论