How to stream an MP3 from an ASP.NET MVC Controller Action

前端 未结 7 1641
时光说笑
时光说笑 2020-12-29 16:31

I have an mp3 file in my site. I want to output it as a view. In my controller I have:

public ActionResult Stream()
{
        string file = \'test.mp3\';
            


        
7条回答
  •  温柔的废话
    2020-12-29 17:16

    Why not use the Filepathresult?

    Like this :

            public FilePathResult DownLoad()
        {
            return new FilePathResult(Url.Content(@"/Content/01.I Have A Dream 4'02.mp3"), "audio/mp3");
        }
    

    And create the download link:

    <%=Html.ActionLink("Download the mp3","DownLoad","home") %>
    

提交回复
热议问题