【发布时间】:2021-10-21 06:42:11
【问题描述】:
我想制作一个模型,从动态字符串对象中获取所有 html 代码。像这样:
动态 html 模型:
public class PageHtmlModel
{
public string HtmlCode { get; set; }
}
实体模型
public class Entity
{
private int _ID;
private string _Module;
private string _Explanation;
private string _Situation;
private string _Personel;
private string _PersonelsNotes;
private string _EndDate;
public int id { get => _ID; set => _ID = value; }
public string module { get => _Module; set => _Module = value; }
public string explanation { get => _Explanation; set => _Explanation = value; }
public string situation { get => _Situation; set => _Situation = value; }
public string personel { get => _Personel; set => _Personel = value; }
public string personels_notes { get => _PersonelsNotes; set => _PersonelsNotes = value; }
public string end_date { get => _EndDate; set => _EndDate = value; }
}
DataAccesLayer:
public static string html()
{
PageHtmlModel pageHtmlModel = new PageHtmlModel();
//Thats All html page comes from string
pageHtmlModel.HtmlCode = "@model deneme100.Models.Entity <html> <head> <link href='~/css/invoice.css' rel='stylesheet' /> </head> <body> <div class='index-box'> <table cellpadding='0' cellspacing='0'> <tr class='top'> <td colspan='2'> <table> <tr> <td class='title'> <img src='~/img/logo.png' style='width:100%; max-width:300px;' /> </td> <td> @Html.DisplayNameFor(model => model.id):@Html.Raw(Model.id) <br>@Html.DisplayNameFor(model => model.module):@Html.Raw(Model.module) <br>@Html.DisplayNameFor(model => model.explanation):@Html.Raw(Model.explanation) </td> </tr> </table> </td> </tr> <tr class='information '> <td colspan='2 '> <table> <tr> <td> @Html.DisplayNameFor(model => model.situation):@Html.Raw(Model.situation) <br>@Html.DisplayNameFor(model => model.end_date):@Html.Raw(Model.end_date) </td> <td> </td> </tr> </table> </td> </tr> <tr class='heading '> <td> @Html.DisplayNameFor(model => model.personels_notes) </td> <td></td> </tr> <tr class='item'> <td> @Html.Raw(Model.personels_notes) </td> </tr> <tr class='total '> <td></td> <td> @Html.DisplayNameFor(model => model.personel):@Html.Raw(Model.personel) </td> </tr> </table> </div> </body> </html>";
return (pageHtmlModel.HtmlCode);
}
这是我打开其他动态模型页面的索引页面
//This is catching object id for entity object
$('#myTable tbody').on('click', '#pdf', function () {
if (!($(this).closest('tr').hasClass('selected'))) {
table.$('tr.selected').removeClass('selected');
$(this).closest('tr').addClass('selected');
}
obj = {}
obj.id = $('tr.selected td').eq(0).html();
window.location = "/Home/PDF/" + obj.id;
if ($(this).closest('tr').hasClass('selected')) {
$(this).closest('tr').removeClass('selected');
}
})
控制器
public IActionResult PDF(int id)
{
var result = new EntityDataAccess.DataObject();
result.data = EntityDataAccess.OneObject(new Entity() { id = id });
return View(EntityDataAccess.html(), result.data[0]);
}
查看 => 我只想写这个并查看我的所有 html 页面
@model myProject.Models.PageHtmlModel
@{
ViewData["Title"] = "PDF";
Layout = null;
}
感谢您从现在开始的帮助
【问题讨论】:
-
还有什么可以帮助您的吗?
标签: model-view-controller model asp.net-core-mvc asp.net-core-3.1 jsreport