0

私はこのアクションメソッドを持っています

[HttpPost]
public ActionResult CreateEsf(EsfLotDetailsModel model)
{
   ...
}

このモデルには 2 つのプロパティがあります。1 つはデータベース POCO オブジェクトで、もう 1 つはリストです。このメソッドに相当する GET では、これらの値はすべて正しく設定されていましたが、投稿時にこれらは null (POCO) および空 (リスト) に設定されます。

これはなぜでしょうか?

私の見解はこちら

@using UI.Helpers

@model UI.Areas.Admin.Models.EsfLotDetailsModel

@{
    ViewBag.Title = "Create Forward Lot";

}

<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/AdminDesignTheme/js/wl_Date.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Content/AdminDesignTheme/js/wl_Time.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.mousewheel.min.js")" type="text/javascript"></script>

@{
        <script type="text/javascript">
            $(document).ready(function () {
                var options = {
                    dateFormat: "dd/mm/yy"
                };
                $('#Starts').wl_Date(options);
                $('#Ends').wl_Date(options);
                $('#startTime').wl_Time();
                $('#endTime').wl_Time();
            });
        </script>
}

<p>@Html.ActionLink("Back to Item List", "Index","Inventory")</p>

@Html.ValidationSummary(true, "Please correct the errors and try again.")
@using (Html.BeginForm(new {model = @Model})) {

    @Html.HiddenFor(model => model.Auction.InventoryReference)
    @Html.HiddenFor(model => model.Auction.Title)
    @Html.HiddenFor(model => model.Auction.Description)
    <fieldset>
        <legend></legend>
        <label>ESF Lot Information</label>            

        <section>
            @Html.LabelFor(model => model.Auction.Title)
            <div> @Html.DisplayFor(model => model.Auction.Title) 
            @Html.ValidationMessageFor(model => model.Auction.Title)    </div>   
        </section>

        <section>
             @Html.LabelFor(model => model.Auction.Description)
             <div> @Html.DisplayFor(model => model.Auction.Description) 
             @Html.ValidationMessageFor(model => model.Auction.Description)     </div>  
        </section>

        @if (HttpContextHelper.IsUserAdmin())
        {<section>
             <label for="IsFeatured">Is Featured <i>(displayed in homepage)</i></label>
             <div> @Html.CheckBoxFor(model => model.Auction.IsFeatured) 
             @Html.ValidationMessageFor(model => model.Auction.IsFeatured)     </div>  
        </section>
        }
        else
        {
            <section>
             <label for="IsFeatured">Is Featured <i>(displayed in homepage)</i></label>
             <div> @Html.CheckBoxFor(model => model.Auction.IsFeatured, new { disabled = "disabled" }) (Contact Admin to make this a featured lot) 
             @Html.ValidationMessageFor(model => model.Auction.IsFeatured)     </div>  
            </section>

        }

        @if (HttpContextHelper.IsUserAdmin())
        {<section>
             @Html.Label("VAT Applicable")
             <div> @Html.CheckBoxFor(model => model.Auction.VatApplicable) 
             @Html.ValidationMessageFor(model => model.Auction.VatApplicable)     </div>  
        </section>
        }
        else
        {
            <section>
             @Html.Label("VAT Applicable")
             <div> @Html.CheckBoxFor(model => model.Auction.VatApplicable, new { disabled = "disabled" }) (Contact Admin if it is not VATable) 
             @Html.ValidationMessageFor(model => model.Auction.VatApplicable)     </div>  
            </section>

        }

    </fieldset>

    <fieldset>
        <legend></legend>
        <label>Date and Time</label>

        <section>
             <label>Starts <em>(dd/mm/yy hh:mm)</em></label>
             <div> <input type="text" class="date" id="Starts" /> 
                <input type="text" class="time" data-connect="Starts" id="startTime" /> 

             @Html.ValidationMessageFor(model => model.Auction.Starts)       </div>
        </section>

        <section>
             <label>Ends <em>(dd/mm/yy hh:mm)</em></label>
             <div> <input type="text" class="date" id="Ends" /> 
                   <input type="text" class="time" data-connect="Ends" id="endTime" /> 

             @Html.ValidationMessageFor(model => model.Auction.Ends)   </div>    
        </section>
        <section>
             @Html.LabelFor(model => model.Auction.IsExtensible)
             <div> @Html.CheckBoxFor(model => model.Auction.IsExtensible) 
             @Html.ValidationMessageFor(model => model.Auction.IsExtensible)     </div>  
        </section>
    </fieldset>
    <fieldset>
        <legend></legend>
        <label>Bid Options</label>

        <section>
             @Html.LabelFor(model => model.Auction.StartingBid)
             <div> @Html.TextBoxFor(model => model.Auction.StartingBid) 
             @Html.ValidationMessageFor(model => model.Auction.StartingBid)     </div>  
        </section>

        <section>
             @Html.LabelFor(model => model.Auction.Reserve)
             <div> @Html.TextBoxFor(model => model.Auction.Reserve) 
             @Html.ValidationMessageFor(model => model.Auction.Reserve)   </div>    
        </section>

        <section>
             <label>Reserve Visible <em>(Displays as Reserve met or not met)</em></label>
             <div> @Html.CheckBoxFor(model => model.Auction.ReserveVisible) 
             @Html.ValidationMessageFor(model => model.Auction.ReserveVisible)  </div>     
        </section>

        <section>
             @Html.LabelFor(model => model.Auction.IsBidIncrementPercentual)
             <div> @Html.CheckBoxFor(model => model.Auction.IsBidIncrementPercentual) 
             @Html.ValidationMessageFor(model => model.Auction.IsBidIncrementPercentual)     </div>  
        </section>  

        <section>
             @Html.LabelFor(model => model.Auction.BidIncrement)
             <div> @Html.TextBoxFor(model => model.Auction.BidIncrement, new { @Value = 1m })
             @Html.ValidationMessageFor(model => model.Auction.BidIncrement)        </div>
        </section>              

        <section>
             @Html.LabelFor(model => model.AuctionEvents)
             <div> @Html.DropDownList("Auction", Model.AuctionEvents, "Select auction", new { required = "required" }) 
             @Html.ValidationMessageFor(model => model.AuctionEvents)       </div>
        </section>

        <section>
            <div><button>Create</button></div>
        </section>        

    </fieldset>
}

<div>
    @Html.ActionLink("Back to Item List", "Index","Inventory")
</div>
4

3 に答える 3

0

これらのオプションはどれも機能しませんでした。代わりに、POCO オブジェクトのすべての値をモデルに個別に配置し、POCO オブジェクトを削除しました。なぜ機能しないのかわかりません。

于 2012-10-16T17:07:16.340 に答える
0

FormMethod = FormMethod.Post を Html.BeginForm() に追加します

@using (Html.BeginForm("Action", "Controller",FormMethod.Post))
{

}
于 2012-10-16T15:06:55.167 に答える
0

送信ボタンはどこにありますか?

@using (Html.BeginForm("Action", "Controller",FormMethod.Post))
{
  ...
  <input type="submit" value="submit" />
}

フォームに入力したら送信ボタンを押し、[HttpPost]メソッドに入力するとModelの値が入力されます。

于 2012-10-16T15:27:52.550 に答える