سؤال

This is my code. I have written in MVC3 to download image file, *.pdf file or *.docx file on click.

Variable agreefile defined in foreach loop store path of image file, pdf file and word file. Now I want to download items when user clicks on any item from my view page.

@foreach (string agreefile in Model.SAgreement)
{
    <div style="width:100px;height:150px;display:inline-block;margin:10px 5px;">
        @*<img src="@agreefile" style="height:150px; width:100px" alt=""/>*@
        <object data=@agreefile" type="application/docx" width="300" height="200">
            alt : <a href="@agreefile">test</a>
        </object>
    </div> 
}
هل كانت مفيدة؟

المحلول

The solution would be to have a button that triggers an action on the controller that returns a file. (you need to change the mime type depending on what you are returning)

Something like this:

    public ActionResult GetFile()
    {
            //...
            return File(filePath, "application/pdf", fileDownloadName);
    }
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top