亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

請問MVC表單無法發布對象列表

請問MVC表單無法發布對象列表

海綿寶寶撒 2019-08-01 02:01:16
MVC表單無法發布對象列表所以我有一個MVC ASP.NET應用程序有問題。本質上,我有一個視圖,它包含一個表單,它的內容被綁定到一個對象列表中。在這個循環中,它加載PartialView中正在循環的項?,F在一切都在運轉,直到形體被提交。當提交時,控制器將被發送一個空對象列表。下面的代碼證明了這些問題。家長意見:@model IEnumerable<PlanCompareViewModel>@using (Html.BeginForm("ComparePlans", "Plans", FormMethod.Post, new { id = "compareForm" })){<div>     @foreach (var planVM in Model)     {         @Html.Partial("_partialView", planVM)     }</div>}_ParalView:@model PlanCompareViewModel<div>     @Html.HiddenFor(p => p.PlanID)     @Html.HiddenFor(p => p.CurrentPlan)     @Html.CheckBoxFor(p => p.ShouldCompare)    <input type="submit" value="Compare"/></div>以下是上述代碼的類:PlanViewModel:public class PlansCompareViewModel{     public int PlanID { get; set; }     public Plan CurrentPlan { get; set; }     public bool ShouldCompare { get; set; }     public PlansCompareViewModel(Plan plan)     {         ShouldCompare = false;         PlanID = plan.PlanId;         CurrentPlan = plan;     }     public PlansCompareViewModel()     {         // TODO: Complete member initialization     }     public static IEnumerable<PlansCompareViewModel> CreatePlansVM(IEnumerable<Plan> plans)     {         return plans.Select(p => new PlansCompareViewModel(p)).AsEnumerable();     }}主計長:public class PlansController : MyBaseController{     [HttpPost]     public ActionResult ComparePlans(IEnumerable<PlanCompareViewModel> model)     {          //the model passed into here is NULL     }}問題在于控制器的作用。據我所知,它應該發布一個PlanCompareViewModel的可枚舉列表,但它是空的。在檢查發送的POST數據時,它發送的是正確的Params。如果我要將‘IEnDigable’改為‘FormCollection’,它包含正確的值。有人知道為什么綁定器沒有創建正確的對象嗎?我可以使用javascript繞過這個問題,但這違背了目的!任何幫助都將不勝感激!
查看完整描述

2 回答

  • 2 回答
  • 0 關注
  • 669 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號