美好的一天,我读过一篇文章http://www.codeproject.com/Articles/260470/PDF-reporting-using-ASP-NET-MVC3,并尝试在我的测试项目中使用它,一切都很完美。但是当我将它添加到我的主项目时,我遇到了一个错误
“/”应用程序中的服务器错误。
无法找到该资源。
说明:HTTP 404。您要查找的资源(或其依赖项之一)可能已被删除、名称已更改或暂时不可用。请查看以下 URL 并确保其拼写正确。
请求的网址:/TextSharp
而且我不知道我哪里错了。有任何想法吗?
添加
控制器
public class TextSharpController : PdfViewController
{
private UniversityRepository repo = new UniversityRepository();
//
// GET: /TextSharp/
public ActionResult Index()
{
var model = repo.GetStudents().ToList();
return this.ViewPdf("Test report", "Index", model, 39);
}
}
看法
@model Project.Web.Models.Entities.Student
@{
ViewBag.Title = "Index";
}
<h2>Index</h2>
<fieldset>
<legend>Student</legend>
<div class="display-label">
@Html.DisplayNameFor(model => model.ApplicationNumber)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.ApplicationNumber)
</div>
<div class="display-label">
@Html.DisplayNameFor(model => model.LastName)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.LastName)
</div>
<div class="display-label">
@Html.DisplayNameFor(model => model.FirstName)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.FirstName)
</div>
<div class="display-label">
@Html.DisplayNameFor(model => model.MiddleName)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.MiddleName)
</div>
<div class="display-label">
@Html.DisplayNameFor(model => model.PersonalCode)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.PersonalCode)
</div>
<div class="display-label">
@Html.DisplayNameFor(model => model.Nationality)
</div>
<div class="display-field">
@Html.DisplayFor(model => model.Nationality)
</div>
</fieldset>
<p>
@Html.ActionLink("Edit", "Edit", new { id=Model.StudentId }) |
@Html.ActionLink("Back to List", "Index")
</p>
全球.asax
public class MvcApplication : System.Web.HttpApplication {
public static void RegisterGlobalFilters(GlobalFilterCollection filters) {
filters.Add(new HandleErrorAttribute());
}
public static void RegisterRoutes(RouteCollection routes) {
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default", // Route name
"{controller}/{action}/{id}", // URL with parameters
new { controller = "Home", action = "Index", id = UrlParameter.Optional } // Parameter defaults
);
routes.MapRoute(
"TextSharp",
"{controller}/{action}/{id}",
new {controller = "TextSharp", action = "Index", id = UrlParameter.Optional}
);
}
protected void Application_Start() {
AreaRegistration.RegisterAllAreas();
//WebApiConfig.Register(GlobalConfiguration.Configuration);
//FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
//Database.SetInitializer<UniversityContext>(new UniversityInitializer());
RouteConfig.RegisterRoutes(RouteTable.Routes);
//RegisterGlobalFilters(GlobalFilters.Filters);
//RegisterRoutes(RouteTable.Routes);
}
}