作为一个小故事,我想用我的视图上的一些数据生成一个PDF.所有数据都存储在模型中.因此,在提交按钮上,单击生成PDF按钮,我想将模型传递给控制器.
Model:
个
public class Analytics
{
public int Total { get; set; }
public int y { get; set; }
public int x { get; set; }
}
View.cshtml:
@model Analytics <!--this one contains all my data I need-->
<!--Display data on page->>
<p> @model.Total </p>
<p> @model.y </p>
<p> @model.x </p>
<form action="@Url.MyAction("GeneratePDF", "Analytics", @Model)" method="post">
<button type="submit">Generate PDF</button>
</form>
AnalyticsController.cs
:
[HttpPost]
public IActionResult GeneratePDF(Analytics analytics)
{
// here is the problem, analytics is null..
return View();
}
我不明白为什么分析率是null
.我的观点有什么问题吗?