The best way to display pictures is of course img SRC directly points to the address, simple and practical. But sometimes the way to display pictures using picture streams is also used. The implementation is also relatively simple (in C # MVC, Java does not understand). Specific as follows:
1. Front desk cshtml part
Adds an IMG tag whose address points back to the background of the method that returns the picture stream.
<span id= "__kindeditor_bookmark_ start_14__ "></span>
@Url. Action method has three parameters, method name, control name, method parameter (parameter type not written)
2. Background Control Section
<summary>///Local picture///</summary>///<returns></returns>public fileresult ShowImage (string ID) { string _path = string. Concat (System.AppDomain.CurrentDomain.BaseDirectory, "content\\images\\longmao.png"); FileStream fs = new FileStream (_path, FileMode.Open); byte[] Bydata = new Byte[fs. Length]; Fs. Read (bydata, 0, bydata.length); Fs. Close (); Return File (Bydata, "image/jpg");}
The return value type is fileresult, not our common actionresult, and the return is also return File (). About the different return types of MVC, you can learn about the Internet.
In particular, this kind of image display method is not recommended, the use of relatively more troublesome.
C#mvc displaying a picture using a binary stream