2017-02-02 23 views
0

これに関連して報告されている多くの問題を読んだことがありますが、問題は解決していません。MVC POSTはモデルをバインドしません...結果はnullです

モデル:

public class MySoftwareResults 
{ 
    public Shopping_MachineInformation MachineInformation { get; set; } 
    public ShoppingUserInformation UserInformation { get; set; } 
    public List<Shopping_MySoftwareResults> ApplicationsList { get; set; } 
    public string Requester { get; set; } 

    public MySoftwareResults() 
    { 
     MachineInformation = new Shopping_MachineInformation(); 
     UserInformation = new ShoppingUserInformation(); 
     ApplicationsList = new List<Shopping_MySoftwareResults>(); 
     Requester = ""; 
    } 
} 

フォーム:

@using (@Html.BeginForm("MySoftwareResults", "Client", FormMethod.Post)) 
    { 
     <div class="form-group"> 
      <table class="table table-responsive list-view"> 
       <thead> 
       <tr> 
        <th>Software</th> 
        <th>Cost</th> 
        <th>Requires Approval</th> 
        <th>Status</th> 
        <th>Select</th> 
       </tr> 
       </thead> 
       <tbody> 
       @foreach (var item in Model.ApplicationsList) 
       { 
        <tr> 
         <td> 
          @Html.LabelForModel(item.Software) 
         </td> 
         <td>@Html.LabelForModel(item.Cost)</td> 
         <td> 
          @Html.LabelForModel(item.RequiresApproval) 
         </td> 
         <td>@Html.LabelForModel(item.Status)</td> 
         <td> 
          <input type="checkbox" id="Selected" name="Selected" value="@item.CollectionID"/> 
         </td> 
        </tr> 
       } 
       </tbody> 
      </table> 
     </div> 
     <div class="form-group"> 
      <input type="submit" title="SUBMIT" class="btn btn-primary pull-right" id="butSubmit" /> 
     </div> 
    } 

フォームが完全に読み込まれます。私はモデルが空で送信をクリックすると:

[HttpPost] 
public ActionResult MySoftwareResults(MySoftwareResults results) 
{    
    var selected = axp.euc.sdsassistance.core.Queries.Shopping_ParseCheckedItems(Request.Form["Selected"]);... 
} 

私はバイオリンを使用してみましたが、私は、フォームのロードパスされたモデルデータを反映するために何かを見つけることができません。

私は困惑しています。

+0

Request.Form []で値を使用する前に、値に 'name'属性を付ける必要があります。これが組み込みのHtml.LabelForModelで動作するかどうか不明です。 – Laurens

+0

それはそれだとは思わない。もともと私はチェックボックスの問題を解決していました。私はそれを把握し、Request.Form []にはそのデータが含まれています。その例では、チェックボックスの問題を解決するためにモデルをポストにバインドしました。しかし、私のアプリケーションではそうではありません。 – Edmound

+0

あなたのモデルと関係のないあなたの生成HTML。生成する唯一の入力は 'name =" Selected "を持ち、' ​​public ActionResult MySoftwareResults(bool [] selected) 'にバインドするだけで無駄になります。コレクションにバインドする方法については、[この回答](http://stackoverflow.com/questions/30094047/html-table-to-ado-net-datatable/30094943#30094943)を参照してください。そしてフォームは成功したコントロール( ''、 '