0

MVC 1の新機能です。

私のプロジェクトでは、 IList をモデルに割り当て、 forloop を使用して Textbox 、 dropdox などに割り当てています...ユーザーは要件に従って値を変更できます。私が欲しいのは、ユーザーがページの上部にある [すべて保存] ボタンをクリックしたときに、ILIST の形式で aspx ページに存在する値を取得する方法です。

ここに、フォームの入力に使用するコードがあります....

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">
                       <% using (Html.BeginForm("MyController", "EditCopyRestaurantMealRate", FormMethod.Post, new { id = "frmEditCopyRestaurantMealRate" }))
{ %>

<%= Html.Submit("Save All Services", ApplicationPermissions.ManageContract, new { name = "submitButton" })%>

<table width="100%" class="edit_restaurant_form">
<col width="19%" />
<col width="30%" />
<col width="19%" />
<col width="*" />
  foreach (var item in Model)
    {       
%>
<tr> 
        <th>
            <label for="DateFrom">
                Effective from:</label>&nbsp;<label class="mandatory">*&nbsp;</label>
        </th>
        <td>
            <% string dtFrom = "";

               dtFrom = item.Datefrom.ToString("dd-MMM-yyyy");
            %>
            <%= Html.TextBox("DateFrom", dtFrom)%>
        </td>
        <th>
            <label for="DateTo">
                Effective to:</label>&nbsp;<label class="mandatory">*&nbsp;</label>
        </th>
        <td>
            <% string dtTo = "";
               dtTo = item.Dateto.ToString("dd-MMM-yyyy");
            %>
            <%= Html.TextBox("DateTo", dtTo)%>
        </td>
    </tr>
<%  }      
%>

ここにコントローラーコードがあります。

public ActionResult MyController(string submitButton, IList<CMS.Model.VcmsRestaurant> AddendumMealRates)
{
    // Need to receiv all value in list which is edited

    return View(@"~\index.aspx", AddendumMealRates);
}

MyControllerユーザーがページで編集する値を取得するにはどうすればよいですか?

4

2 に答える 2

0

ポストバックをキャッチするメソッドをコントローラーに作成します。

単純なデータの場合は、次のようなことができます。

public ActionResult EditRestaurant(string dateFrom, string dateTo)
{
    // do something with the values here.
}

または、より複雑なデータをカプセル化できるビューモデルを作成します。

public ActionResult EditRestaurant(EditRestaurantViewModel editRestaurantVM)
{
    // do something with the values here.
}

アイテムのリストをポストバックしようとしていることがわかるので、テーブルで、これを回答に追加します。

私の知る限り、データの構造を簡単にポストバックすることはできません。Knockout.js などの JavaScript ライブラリを使用するか、生の javascript/jquery を使用してデータを収集し、AJAX で送り返す必要があります。

于 2013-07-22T07:33:59.443 に答える