且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何Url.Action工作Asp.net MVC?

更新时间:2022-11-23 09:49:35

这将构建路径行动,返回一个URL,执行操作的不结果。

It will construct the path to the action, returning a url, not the results of executing the action.

结果将是:

<td>
   <img src='/User.mvc/DisplayImage?id=U00915441' alt="" />
</td>

举例code。假设你的用户模型存储在一个字节数组中的形象。如果您在使用LINQ和属性是二进制,然后用()将其转换为一个字节数组方法。请注意,这将要求用户在使用GET请求记录的属性。

Example code. assumes your user model has the image stored in a byte array. If you are using LINQ and the property is a Binary, then use the ToArray() method to convert it to a byte array. Note the attributes which will require that the user be logged in and using a GET request.

[Authorize]
[AcceptVerbs( HttpVerbs.Get )]
public ActionResult DisplayImage( string id )
{
     var user = ...get user from database...

     return File( user.Image, "image/jpeg" );
}

}