How does Url.Action work Asp.net MVC?

后端 未结 1 1856
一生所求
一生所求 2021-02-13 19:45

This is somewhat related to another question I\'ve asked but I figure why not ask it seperately.

If I were to place something like the following in a view



        
1条回答
  •  梦谈多话
    2021-02-13 20:29

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

    The results will be:

    
       
    
    

    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" );
    }
    

    }

    0 讨论(0)
提交回复
热议问题