Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to handle different ActionResults for an ASP.NET MVC Controller Action
    text
    copied!<p>I have a not-so-ideal situation where uploaded files are stored on an internal network share. So in the database I'm storing the path to where the file was saved, but it's quite possible for the file to get deleted out of sync of the database. So in a Controller action I lookup the upload information and perform checks that things are correct. It can be summed up as something like this:</p> <pre><code>public ActionResult GetUploadedFile(int uploadId){ var uploadedFile = Repository&lt;Upload&gt;.FirstOrDefault(upload =&gt; upload.ID == uploadID); if(uploadedFile == default(Upload)){ return View("InvalidUpload"); } if(File.Exists(uploadFile.Path)){ var fileInfo = new FileInfo(uploadFile.Path); var contentType = HttpContext.GetMimeTypeForFileInfo(fileInfo) // my lookup extension method return File(uploadFile.Path, contentType, uploadFile.Name); } return View("InvalidUpload"); } </code></pre> <p>The problem is that this action is currently accessible via a link on a view that is loaded through AJAX. So when the file does exist and everything's OK, it will bring up the standard "What do you want to do with this file" dialog in the browser and keep the content visible to the user. The issue is the other paths through the code. Returning the view takes the user to a completely new URL. And then clicking back will reset where they were (it's basically dynamic jQuery Tabs, so nothing huge, but still still a major inconvience).</p> <p>So I'm looking for how others may have tackled this situation as it doesn't seem to be uncommon. Or even some feedback to make this a little more user friendly. I don't have a say in where the file is stored, so changing that is not an option.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload