2013-04-21 73 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