iTextSharp控制器无法找到资源

时间:2013-07-30 08:49:06

标签: asp.net asp.net-mvc asp.net-mvc-3 razor itextsharp

美好的一天,我读了一篇文章http://www.codeproject.com/Articles/260470/PDF-reporting-using-ASP-NET-MVC3,并尝试在我的测试项目中使用它,一切都很完美。但是,当我将其添加到我的主项目时,我有一个错误

应用程序中的服务器错误。

无法找到资源。

描述:HTTP 404.您正在查找的资源(或其中一个依赖项)可能已被删除,名称已更改或暂时不可用。请查看以下网址,确保拼写正确。

请求的网址:/ 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>

Global.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);
    }
}

0 个答案:

没有答案