Asp.net 如何在.Net Core MVC中将字符串数据导出为pdf格式

Asp.net 如何在.Net Core MVC中将字符串数据导出为pdf格式,asp.net,Asp.net,如何在.Net Core MVC中将字符串数据导出为pdf格式。请任何人帮助我在.net core中导出pdf格式的数据。您可能能够在OnResultExecuting期间点击响应,并使用将结果HTML存储在MemoryStream中的内容替换Filter属性。然后,您可以在OnResultExecuted期间清除响应,并将其替换为PDF转换的结果。不过,我不确定这是否比仅仅从URL获取HTML要好 乙二醇= 使用系统; 使用System.Collections.Generic; 使用Syste

如何在.Net Core MVC中将字符串数据导出为pdf格式。请任何人帮助我在.net core中导出pdf格式的数据。

您可能能够在OnResultExecuting期间点击响应,并使用将结果HTML存储在MemoryStream中的内容替换Filter属性。然后,您可以在OnResultExecuted期间清除响应,并将其替换为PDF转换的结果。不过,我不确定这是否比仅仅从URL获取HTML要好

乙二醇=

使用系统;
使用System.Collections.Generic;
使用System.Linq;
使用System.Web;
命名空间WebApplication2.Models
{
公共阶层人士
{
公共字符串名称{get;set;}
公共字符串电子邮件{get;set;}
公共整数{get;set;}
}
}
公共行动结果GetPersons()
{
列表人员=新列表();
添加(newperson(){Age=29,Name=“Rami1”,Email=”Rami1@abc.com" });
添加(newperson(){Age=28,Name=“Rami2”,Email=”Rami2@abc.com" });
返回视图(人);
}
@模型IEnumerable
@{
ViewBag.Title=“GetPersons”;
}
GetPersons
@DisplayNameFor(model=>model.Name)
@DisplayNameFor(model=>model.Email)
@DisplayNameFor(model=>model.Age)
@foreach(模型中的var项目){
@DisplayFor(modelItem=>item.Name)
@DisplayFor(modelItem=>item.Email)
@DisplayFor(modelItem=>item.Age)
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebApplication2.Models
{
    public class Person
    {
        public string Name { get; set; }
        public string Email { get; set; }
        public int Age { get; set; }
    }
}



 public ActionResult GetPersons()
        {
            List<Person> persons = new List<Person>();
            persons.Add(new Person() { Age = 29, Name = "Rami1", Email = "Rami1@abc.com" });
            persons.Add(new Person() { Age = 28, Name = "Rami2", Email = "Rami2@abc.com" });
            return View(persons);
        }

@model IEnumerable<WebApplication2.Models.Person>

@{
    ViewBag.Title = "GetPersons";
}

<h2>GetPersons</h2>

<table class="table">
    <tr>
        <th>
            @Html.DisplayNameFor(model => model.Name)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Email)
        </th>
        <th>
            @Html.DisplayNameFor(model => model.Age)
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Email)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Age)
        </td>
    </tr>
}

</table>