How would I show a PDF/ Doc /Text File, in a PopUP window instead of allowing users to download it ?
These files path is stored in a database table and in my ASP.NET MVC 2.0 Project I have a folder named " Files" where my actual files are stored .
I have a Telerik MVC Grid where there is a column named AssociatedFiles 开发者_运维问答and in this column there is a ClientTemplate such as " View File ". Once someone clicks on this Link , actual file associated with that RowID should be displayed in a PopUP instead of allowing users to download it .
Using FilePathResult I can allow my users to download it but I dont want this . I want users to view that perticular File in a PopUp Window .
I searched alot for the associated code for this perticular scenario but couldnt find anything usefull . Please Help me with actual working codes. Send your comments @ ashes22@gmail.com
Add a partial View to your View Folder named " FilePopUp" . Here use Telerik Window Control
Code :-
<% Html.Telerik().Window()
.Name("PopupWindow")
//.Title("View PDF")
//.Icon(Url.Content("~/Content/Common/Icons/favicon.png"), "favicon")
.LoadContentFrom(Model.PDFFilePath).Modal(true)
.Buttons(buttons => buttons.Close(Url.Action("Controller", "Action")))
//.Buttons(buttons => buttons.Maximize(Url.Action("Controller")).Close(Url.Action("Controller", "Action")))
.Scrollable(false)
.Resizable()
.Draggable(true)
.Width(870)
.Height(500)
.Render();
%>
In your Controller :-
public ActionResult GetPdffile(string id)
{
try
{
FilePathAdmin filePath = new FilePathAdmin();
filePath.ERAPDFFilePath = this.WorkerService.GetPdfFilepath(id);
//string filepath = this.WorkerService.GetPdfFilepath(ID);
return PartialView("PopUpWindow", filePath);
}
catch (Exception ex)
{
bool reThrow = ExceptionPolicyWrapper.HandleException(ex, ExceptionPolicies.MVCPolicy);
if (reThrow)
throw;
}
return null;
}
In your Model Class , create another Class named " FilePathAdmin" and write following code in it
public class FilePathAdmin
{
public string ERAPDFFilePath { get; set; }
}
And thats it .. You are done
精彩评论