2017-06-19 3 views
0

Dies ist mein Controller-Aktion MethodeFehler, während die Daten an die Steuerung aus Sicht vorbei

[HttpPost] 
     public ActionResult UpdateOrder(List<State> objState) 
     { 
      DataTable dst_state = new DataTable(); 
      dst_state.Columns.Add("state_id", typeof(int)); 
      dst_state.Columns.Add("state_order_by", typeof(int)); 
      foreach (var abc in objState) 
      { 
       DataRow dr = dst_state.NewRow(); 
       dr["state_id"] = abc.state_id; 
       dr["state_order_by"] = abc.state_order; 
       dst_state.Rows.Add(dr); 
      } 
      State.UpdateOrderState(dst_state); 
      TempData["message"] = "Order Updated Successfully"; 
      return View("ViewState"); 
     } 

dies ist meiner Ansicht

@model dsmanager.Models.State 
    @using PagedList.Mvc; 
    @using dsmanager.Controllers; 
    @using dsmanager.DLL; 

    @using (Html.BeginForm("UpdateOrder", "State", FormMethod.Post, new { enctype = "multipart/form-data" })) 
    { 
     Html.AntiForgeryToken(); 
     Html.EditorForModel(); 
     ViewBag.Title = "View State"; 

     @*<script type="text/javascript"> 
      function GetList() { 
       var active = "0" 
       var inactive = "0" 
       $("#loading").show(); 

       var param = { active: active, inactive: inactive } 
       $.ajax({ 
        type: 'POST', 
        dataType: 'html', 
        url: '/State/GetStateData', 
        data: param, 
        success: function (Data) { 
         $("#loading").hide(); 
         $("#divpartialTable").empty(); 
         $("#divpartialTable").html(Data); 
        }, 
        error: function (XMLHttpRequest, textStatus, errorThrown) { 
         $("#loading").hide(); 
        } 
       }); 
      } 
      </script>*@ 

     <section class="content-header"> 
      <h1>State Details</h1> 
      <ol class="breadcrumb"> 
       <li> 
        <a href="@Url.Action("InsertState", "State")" class="btn btn-danger"><i class="fa fa-plus">&nbsp;Add</i></a> 
       </li> 
      </ol> 
     </section> 
     <div>@Html.DropDownListFor(model => model.state_country_id, Model.Country, "Please Select", new { onchange = "GetList();", @class = "form-control" } ) </div> 
      <br /> 
      <div>@Html.TextBoxFor(model => model.state_name , new { @class = "form-control" })</div> 
      <br /> 
     @*<a id="btnSearch" href="@Url.Action("ViewState", "State")" class="btn btn-danger"><i class="fa fa-plus">&nbsp;Search</i></a>*@ 
     <div class="screen-small"> 
      <section class="content"> 
       <div id="divgrid"> 
        <div id="Addgrid" class="row"> 
         <div class="col-xs-12"> 
          <div class="box box-primary"> 
           <div class="box-header with-border"> 

           </div> 
           <div class="box-body no-padding"> 
            <div> 

            </div> 
            <div class="resp-table"> 
             <div> 
              <table class="table table-striped" cellspacing="0" cellpadding="0" style="border-width:0px;width:100%;border-collapse:collapse"> 
               <thead> 
                <tr class="th" style="white-space:nowrap;"> 
                 <th scope="col">Edit</th> 
                 <th scope="col">ID</th> 
                 <th class="text-left" align="left" scope="col">State Name</th> 
                 <th class="text-left" align="left" scope="col">Country</th> 
                 <th class="text-left" align="left" scope="col">Status</th> 
                 <th class="text-left" align="left" scope="col">Order</th> 
                </tr> 
               </thead> 
               <tbody> 
                @for (int i = 0; i < Model.pagedlist.Count; i++) 
                { 
                 <tr valign="top"> 
                  <td class="text-center" width="20px" data-title="Edit"><a href="@Url.Action("EditState", "State", new { id = Model.pagedlist[i].state_id.ToString() } )"><i class="fa fa-pencil" title="edit"></i>E</a></td> 
                  <td class="text-center" width="20px" data-title="ID">@Html.DisplayFor(model => model.pagedlist[i].state_id)</td> 
                  <td class="text-center" width="100px" style="text-align:left" data-title="ID">@Html.DisplayFor(model => model.pagedlist[i].state_name)</td> 
                  <td class="text-center" width="100px" style="text-align:left" data-title="ID">@Html.DisplayFor(model => model.pagedlist[i].country_name)</td> 
                  <td class="text-center" width="100px" style="text-align:left"> @(Html.DisplayFor(model => model.pagedlist[i].state_status).ToString() == "1" ? "Active" : "Inactive")</td> 
                  <td class="text-center" width="100px" style="text-align:left" data-title="ID">@Html.TextBoxFor(model => model.pagedlist[i].state_order)</td> 
                  <td style="display:none">@Html.HiddenFor(model => model.pagedlist[i].state_id)</td> 
                 </tr> 
                } 
               </tbody> 
               <tr class="th" style="white-space:nowrap;"> 
                <td width="20px"></td> 
                <td width="20px"></td> 
                <td width="100px"></td> 
                <td width="100px"></td> 
                <td width="100px"></td> 
                <td class="text-left" width="100px"> 
                 <input type="submit" value="Update Order" class="btn btn-default" /> 
                </td> 
               </tr> 
              </table> 
             </div> 
            </div> 
           </div> 

           <div class="box-footer text-right"> 
            @*Page @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) of @Model.PageCount*@ 
            @Html.PagedListPager(Model.pagedlist, page => Url.Action("ViewState", new { page })) 
           </div> 
          </div> 
         </div> 
        </div> 
       </div> 

      </section> 

     </div> 
    } 
    <br 

/> 

Während aus Sicht der Datenweitergabe an die Steuerung der Reihenfolge Spalte zu aktualisieren, ich bin Nullenliste im Controller erhalten. Wie man die zwei Felder in der Steuerung liest, um die Reihenfolge zu aktualisieren. Bitte helfen Sie.

Antwort

0

Ihre Parameter für Regler ist nicht Ihr Modell, sollte es sein:

public ActionResult UpdateOrder(dsmanager.Models.State model) 

dann innerhalb der Aktion Eigenschaften mit

zugreifen können
model.state_country_id 
Verwandte Themen