Max*_*mus 0 asp.net-mvc html-helper
我遇到了以下问题:
用户访问网站,点击"添加",然后发送回Controller,模型被检索并再次发送给View.在内部视图中,我检查Model是否为null并显示数据.
@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>
Run Code Online (Sandbox Code Playgroud)
在结束按钮上创建"确认它",单击它后会调用确认方法,但应用变量始终为空.如果我将其值设置为除模型之外的任何值.
[HttpPost]
public ActionResult Confirm(aplikacja app)
{
...
}
Run Code Online (Sandbox Code Playgroud)
在创建按钮"确认它"模型不为空时,我检查了.你碰巧知道出了什么问题吗?
生成的HTML
<form action="/Wydawca/Confirm?app=Adds.Models.aplikacja" method="post">
<input type="submit" value="Zatwierd?" />
Run Code Online (Sandbox Code Playgroud)
本Html.BeginForm应环绕你所有的投入要素,或者它没有任何发布.将您的观点更改为:
@if (Model != null)
{
@using (Html.BeginForm("Confirm", "Wydawca", new { app = @Model }))
{
<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>
@Html.HiddenFor(x => Model.tytul)
@Html.HiddenFor(x => Model.kategoria.nazwa)
@Html.HiddenFor(x => Model.liczba_ocen)
@Html.HiddenFor(x => Model.avg_ocena)
@Html.HiddenFor(x => Model.typ)
<input type="submit" value="Cofirm it" />
</div>
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13451 次 |
| 最近记录: |