前台页面代码
<span style="font-family:SimSun;font-size:18px;">@*上传文件代码,可以实现*@
@using (Html.BeginForm("ProcessRequest", "MongodbHelp", new { actions = "UPLOAD" }, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="file" id="file" />
<input type="submit" value="上传" />
}</span>
显示文件代码
<span style="font-family:SimSun;font-size:18px;"><img src="@ViewData["html"]" /></span>
HomeController
<span style="font-family:SimSun;font-size:18px;"> public ActionResult Index()
{
ViewData["html"] = "/MongodbHelp/ProcessRequest?actions=DOWNLOAD&value=lf.png";
return View();
}
</span>
MongoDBHelpController
<span style="font-family:SimSun;font-size:18px;">using MongoDB.Driver;
using MongoDB.Driver.GridFS;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Mvc;
namespace mvcMongodb.Controllers
{
public class MongodbHelpController : Controller
{
private static MongoDatabase DB;
public static string fileTable = "fs";
//Sets up the environment.