2013-04-21 89 views
2

我想SCR使用Ajax更新的图像,首先在controllor:asp.net MVC - 阿贾克斯更新图像

public ActionResult GenerateMIPImage(float pX = 0, float pY = 0, float pZ = 0) 
    { 
     FileContentResult result; 
     ... 
     im.SetViewPlane(new Point3D(pX, pY, pZ), new Vector3D(0, 0, 1), new Vector3D(0, 1, 0)); 
    ... 
     objImage = im.Bitmap(outputSize, PixelFormat.Format24bppRgb, m); 
     using (var memStream = new MemoryStream()) 
     { 
      objImage.Save(memStream, ImageFormat.Png); 
      result = this.File(memStream.GetBuffer(), "image/png"); 
     } 

     return result; 
    } 

我第一次显示使用图像:

<img src='<%=Url.Action("GenerateMIPImage")%>' alt="" id="dImage"/> 

然后我用这Ajax来改变的变量之一:

​​

图像disapear,当检查其属性,我得到:

http://localhost:59601/�PNG 

我很感谢您的建议,在此先感谢。

回答

1

在你的ajax中,你试图将img的src设置为图像数据而不是图像uri。
而是将img的src设置为ajax请求的url,并将参数添加到地址,并在服务器端将请求方法从post改为get。

dImage.src = '/Home/GenerateMIPImage?'+$.param({ 
        pX: pointXF, 
        pY: pointYF, 
        pZ: pointZF 
       }); 
+0

太谢谢你了穆萨的伟大工程。 – hncl 2013-04-21 16:13:09

-1

请改变你请求的数据部分如下

data: JSON.stringify({ 
        pX: pointXF, 
        pY: pointYF, 
        pZ: pointZF 
       }), 
+0

谢谢Shafqat,不幸的是它没有工作。 – hncl 2013-04-21 16:14:48