模型为null我遇到了以下问题:
用户访问网站,点击“添加”,然后它发回控制器,模型被检索并发送到查看一次。在内部视图中,我检查模型是否为空 并显示数据。模型为Html.BeginForm()ASP.NET MVC
@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>
在结束按钮“确认为”被创建,一旦你点击它调用确认方法,但应用程序变量总是空。如果我将它的价值设置为“模型”,但它可以工作。
[HttpPost]
public ActionResult Confirm(aplikacja app)
{
...
}
当创建按钮“确认”模型不为空,我检查。你碰巧知道发生了什么问题吗?
生成的HTML
<form action="/Wydawca/Confirm?app=Adds.Models.aplikacja" method="post">
<input type="submit" value="Zatwierdź" />
什么是表单标记的呈现html? (不知道你期待'app = @ Model'渲染) – 2014-10-02 12:02:25
'Html.BeginForm'应该环绕所有的输入元素,或者它没有任何可以发布的东西。 – DavidG 2014-10-02 12:06:52
由于您没有编辑任何数据,您为什么需要将整个模型返回(而不是将路径参数设置为模型的唯一ID) – 2014-10-02 12:30:26