So as a short story, I want to generate a PDF with some data I have on my view. All data are stored in the model. So on submit button click of Generate PDF button I want to pass the model to controller.
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();
}
I do not get why the analytics is null. Is something wrong on my view?