0

I have this partial view that displays links to documents;

@model IList<DocumentLineViewModel>
<tr>
    <td class="leftCell" style="width: 150px;">
        <label>Documents</label></td>
    <td class="rightCell" id="documentCell">
        @if (Model.Any(x => x.CurrentUrlFlag))
        {
            foreach (var document in Model)
            {
                 <a target="_blank" href="@document.CurrentUrl">
                     @document.CategoryName
                 </a>
            }
        }
        else
        {
            <span>Not Entered</span>
        }
    </td>
</tr>

If the document is a pdf it works fine, I can view the document. If the document is word (or excel) I get this unwelcome prompt; enter image description here

How do I stop this?

EDIT One way I tried was to embed the document in a popup but this did not work;

@model IList<DocumentLineViewModel>
<tr>
    <td class="leftCell" style="width: 150px;">
        <label>Documents</label></td>
    <td class="rightCell" id="documentCell">
        @if (Model.Any(x => x.CurrentUrlFlag))
        {
            foreach (var document in Model)
            {
                if (document.CurrentUrl.ToUpper().EndsWith("PDF"))
                {
                    <a target="_blank" href="@document.CurrentUrl" class="btn">
                        @document.CategoryName
                    </a>
                }
                else
                {
                    <a href="#show-document" class="btn" data-toggle="modal">@document.CategoryName</a>
                    <div class="modal fade" id="show-document" style="display: none">
                        <object src="@document.CurrentUrl"><embed src="@document.CurrentUrl"></embed></object>
@*                        <iframe src="@document.CurrentUrl"></iframe>*@
                    </div>
                }
            }
        }
        else
        {
            <span>Not Entered</span>
        }
    </td>
</tr>

The popup appeared, but the content did not show the document.

arame3333
  • 9,887
  • 26
  • 122
  • 205
  • 3
    What are you trying to do? A PDF will open in the browser, thus no prompt to download. The browser has no native functionality for viewing `docx` files and so they must be downloaded. As far as I know, you can't override the prompt because it is a safety feature on the users' side. – Inspector Squirrel Dec 04 '14 at 10:03
  • That is what I am trying to do, and the answer is that it can't be done it would seem. – arame3333 Dec 04 '14 at 10:07
  • you can try with [word viewer](http://www.microsoft.com/tr-tr/download/details.aspx?id=4) – asdf_enel_hak Dec 04 '14 at 10:07
  • @arame3333 Siva Gopal has an interesting point in the answer below, if you can find a way to invoke a web document viewer such as Google Docs Viewer, that would certainly be an interesting way around your issue. Your 'links' would probably need to use JavaScript to upload the file to the document viewer via AJAX and then you could probably open the response in an iframe or a modal window or something, that'd be quite cool. – Inspector Squirrel Dec 04 '14 at 10:29
  • My attempted solution did not work, see the edited question to see what I did. – arame3333 Dec 04 '14 at 11:18

1 Answers1

0

As @Sippy suggested, AFAIK there is no native support except PDFs offered by browsers to render documents.

If you can expose your documents for few converters available you may do that as shown in following links:

Google Docs Viewer

SO Post

Display word document on browser (Hope this may help you to an extent)

Community
  • 1
  • 1
Siva Gopal
  • 3,474
  • 1
  • 25
  • 22
  • The Google Docs Viewer does not work, I suspect because the URL is not accessable outside of the VPN I am using. The IFrame and Embed solutions I can't get to work. I have edited my question so you can see what I have done. – arame3333 Dec 04 '14 at 11:17
  • Like I said you would need to upload the document from where it is using Ajax as it won't be accessible :) – Inspector Squirrel Dec 04 '14 at 16:11