0

オブジェクトをパラメーターとして受け入れるビューから編集アクションを呼び出しています。

アクション:

[HttpPost]
    public ActionResult Edit(Organization obj)
    {
        //remove the lock since it is not required for inserts
        if (ModelState.IsValid)
        {
            OrganizationRepo.Update(obj);
            UnitOfWork.Save();
            LockSvc.Unlock(obj);
            return RedirectToAction("List");
        }
        else
        {
            return View();
        }
    }

ビューから:

 @foreach (var item in Model) {

 cap = item.GetValForProp<string>("Caption");
 nameinuse = item.GetValForProp<string>("NameInUse");
 desc = item.GetValForProp<string>("Description");

<tr>
    <td class="txt">
        <input type="text" name="Caption" class="txt" value="@cap"/>
    </td>
    <td>
        <input type="text" name="NameInUse" class="txt" value="@nameinuse"/>
    </td>
    <td>
        <input type="text" name="Description" class="txt" value="@desc"/>
    </td>
   <td>
      @Html.ActionLink("Edit", "Edit", "Organization", new { obj = item as Organization }, null)
   </td>
</tr>

}

例外が発生しています: パラメーター ディクショナリには、'PartyWeb.Controllers.Internal のメソッド 'System.Web.Mvc.ActionResult Edit(Int32)' の null 非許容型 'System.Int32' のパラメーター 'id' の null エントリが含まれています.OrganizationController'. オプションのパラメーターは、参照型または null 許容型であるか、オプションのパラメーターとして宣言する必要があります。パラメータ名: パラメータ

オブジェクトをパラメータとして渡す方法を教えてもらえますか?

4

1 に答える 1

4

オブジェクトをパラメータとして渡す方法を教えてもらえますか?

なぜ ActionLink を使用しているのですか? ActionLink は POST ではなく GET リクエストを送信します。[HttpPost]したがって、ActionLink を使用してアクションが呼び出されるとは思わないでください。HTML フォームを使用し、入力フィールドとして送信するすべてのプロパティを含める必要があります。

そう:

<tr>
    <td colspan="4">
        @using (Html.BeginForm("Edit", "Organization", FormMethod.Post))
        {
            <table>
                <tr>
                @foreach (var item in Model)
                {
                    <td class="txt">
                        @Html.TextBox("Caption", item.GetValForProp<string>("Caption"), new { @class = "txt" })
                    </td>
                    <td class="txt">
                        @Html.TextBox("NameInUse", item.GetValForProp<string>("NameInUse"), new { @class = "txt" })
                    </td>
                    <td class="txt">
                        @Html.TextBox("Description", item.GetValForProp<string>("Description"), new { @class = "txt" })
                    </td>
                    <td>
                        <button type="submit">Edit</button>
                    </td>
                }
                </tr>
            </table>
        }
    </td>
</tr>

また、内部に aを<table>持つことができず、IE などの一部のブラウザーがそれを好まないため、ネストされたを使用したことにも注意してください。<form><tr>

于 2013-06-13T07:18:25.880 に答える