我对 MVC 4 很陌生。我有一个场景,我需要在单独的类中定义一组方法并在控制器中调用所有这些方法。这样我就可以处理与视图不同的功能。
以下是我的代码示例......请查看。
我在控制器下添加了一个新的类文件并定义了如下方法:
public void Convert(ConvertFileOutputType outputType, FileInfo inFile, DirectoryInfo outFolder, int timeout,
int topMargin, int bottomMargin, int leftMargin, int rightMargin)
{
switch (outputType)
{
case ConvertFileOutputType.Pdf:
break;
default: break;
// throw new ConvertFileException(Properties.Resources.OutputTypeNotSupportedWordPerfect);
}
if (converter == null)
{
//converter.LicenseKey = "";
converter = new PdfConverter();
converter.LicenseKey = "";
converter.PdfDocumentOptions.LiveUrlsEnabled = false;
converter.PdfDocumentOptions.PdfPageSize = PdfPageSize.Letter;
converter.PdfDocumentOptions.TopMargin = topMargin;
converter.PdfDocumentOptions.BottomMargin = bottomMargin;
converter.PdfDocumentOptions.LeftMargin = leftMargin;
converter.PdfDocumentOptions.RightMargin = rightMargin;
converter.AvoidImageBreak = true;
}
converter.PdfDocumentInfo.AuthorName = "FileConvert";
converter.PdfDocumentInfo.Title = inFile.Name;
converter.PdfDocumentInfo.CreatedDate = DateTime.Now;
converter.SavePdfFromHtmlFileToFile(inFile.FullName, outFolder + "\\" + inFile.Name + ".pdf");
}
我想在控制器方法中调用上述方法....我盲目地将代码编写为....
public string UploadAsPDF(HttpPostedFileBase fileData)
{
var fileName = this.Server.MapPath("~/uploads/" + System.IO.Path.GetFileName(fileData.FileName));
fileData.SaveAs(fileName);
Convert(outputType, inFile,outFolder,timeout, topMargin, bottomMargin, leftMargin, rightMargin);
return "OK";
}
每当我尝试构建它时,一个类型被用作方法请建议....