私のASPの.Net MVC 2アプリケーションでは、ユーザーはアイテムのリストが表示され、リストがデータベースに保存される前に確認をクリックする必要があります。HttpPostメソッドで確認リスト(IEnumerable)を取得する方法は?
ユーザーが確認をクリックすると、HttpPostメソッドでパラメータがnullになります。 HttpPostメソッドが呼び出されるまではすべて動作します。この時点で、永続化する必要があるリストはnullです。
確認値はどのようにして取得できますか?
私はHttpGetメソッドでTempDataを使用しようとしましたが、HttpPostメソッドではTempDataもnullです。
ここにコントローラコードがあります。
public ActionResult Confirm()
{
List<ConfirmVehicleModel> vehicles = GetAllVehicles();
return View(vehicles);
}
[HttpPost]
public ActionResult Confirm(List<ConfirmVehicleModel> model)
{
//model is null, why ?
UploadVehiclesModelService service = new Models.UploadVehiclesModelService();
service.StoreVehicles(model, User.Identity.Name);
return RedirectToAction("Index", "UploadVehicles");
}
そして、ここで確認ビューは次のとおりです。任意の助け
<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<IEnumerable<RM.Application.Models.ConfirmVehicleModel>>" %>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
Confirm
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<h2>
Confirm that the vehicles below should be added.</h2>
<table>
<tr>
<th>
ReferenceType
</th>
<th>
ReferenceName
</th>
</tr>
<% foreach (var item in Model)
{ %>
<tr>
<td>
<%= Html.Encode(item.ReferenceType) %>
</td>
<td>
<%= Html.Encode(item.ReferenceName) %>
</td>
</tr>
<% } %>
</table>
<div>
<% using (Html.BeginForm())
{ %>
<input type="submit" value="Confirm" />
|
<%= Html.ActionLink("Back to upload form", "Index") %>
<% } %>
</div>
</asp:Content>
おかげで、
種類が
ボブ
こんにちはニコラス、ご返信ありがとうございます。私はHtml.BeginFormを移動しました。パラメータListモードはまだnullです。 FormCollectionもパラメータとして試しましたが、それもnullです。 LABEL要素を使用する必要がありますか? FORM要素は、どのデータをポストバックするのかをどのように知っていますか?ありがとうございますBob –
bobentelect
@bobentelect - あなたはHtml.HiddenFor –
のおかげで、隠し値としてフォーム内の値を埋め込むことができます。 – bobentelect