I encountered following problem:
user visits site, clicks "Add" and then it's sending back to Controller, Model is retrieved and send to View one more time. Inside view, I check whether Model is not null
and displays data.
@if (Model != null)
{
<div id="appInfo">
<table>
<tr>
<th>@Html.DisplayNameFor(x => Model.tytul)</th>
<th>@Html.DisplayNameFor(x => Model.kategoria.nazwa)</th>
<th>@Html.DisplayNameFor(x => Model.liczba_ocen)</th>
<th>@Html.DisplayNameFor(x => Model.avg_ocena)</th>
<th>@Html.DisplayNameFor(x => Model.typ)</th>
</tr>
<tr>
<td>@Model.tytul</td>
<td>@ViewData["kategoria"]</td>
<td>@Model.liczba_ocen</td>
<td>@Model.avg_ocena</td>
<td>@Model.typ</td>
</tr>
</table>
</div>
<div>
@using (Html.BeginForm("Confirm", "Wydawca", new { app = @Model }))
{
<input type="submit" value="Cofirm it" />
}
</div>
At the end button "Confirm it" is created and once you click it invokes Confirm Method but app variable is always null. If I set its value to anything but Model it works.
[HttpPost]
public ActionResult Confirm(aplikacja app)
{
...
}
While creating button "Confirm it" Model is not null, I checked. Do you happen to know what is going wrong?
Generated html
<form action="/Wydawca/Confirm?app=Adds.Models.aplikacja" method="post">
<input type="submit" value="Zatwierdź" />
app = @Modelto render)Html.BeginFormshould wrap around all of your input elements or it has nothing to post.