0

我有这个动作方法

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

我在这个模型中有两个属性。一个是数据库 POCO 对象,另一个是列表。在此方法的 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

将 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 回答
0

这些选项都不起作用。我将 POCO 对象中的所有值分别放在模型中,并删除了 POCO 对象。不知道为什么它不起作用。

于 2012-10-16T17:07:16.340 回答