asp.net mvc 2 - Download the file mvc2 using actionlink -
i want upload , download resume using asp.net mvc2. created codings. uploaded successfully. when try download file have issue.. showing empty page..
controller:
[handleerrorwithajaxfilter] public actionresult uploadresume(httppostedfilebase filedata) { stream fromstream = filedata.inputstream; stream tostream = new filestream(server.mappath("~/content/resumes/") + filedata.filename, filemode.create); loggedincandidate.resumefilename = filedata.filename; //_repository.save(); _userrepository.save(); return json(new jsonactionresult { success = true, message = "resume has been uploaded." }); //return json("resume has been uploaded."); }
view:
<input id="resume" type="file" name="resume" />
download:
<p> <% var link = url.content("~/content/resumes/") + model.resumefilename; %> <a href="<%: link %>">download resume</a> </p>
when click link download resume, shows name of file @ url not downloading.
here how should it. create action in controller this:
public fileresult download(string filename) { var path = path.combine(server.mappath("~/content/resumes/"), filename); var filestream = new filestream(path, filemode.open); // assuming resume ms word document... return file(filestream, "application/vnd.ms-word"); }
and, in view, you'll have:
<p> <%: html.actionlink("download resume", "download", new { filename = model.resumefilename }) %> </p>
Comments
Post a Comment