1

我有一个包含选项卡布局的视图,每个选项卡都包含一个我通过 ajax.beginform 提交的表单。如果模型状态无效,我将返回视图,这是我无法确定如何正确渲染视图的地方。目前,当我提交其中一个表单时,它会在我的选项卡中再次呈现整个页面,这是我不想要的。我认为使用 ajax updatetargetid 我可以呈现需要替换的 div,但正如我所说,它会在我的选项卡中呈现整个页面。

看法

   @model Trakman_Portal_Administration.Models.VehList
   @using Trakman_Portal_Administration.Models

  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  @*<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")"    type="text/javascript"></script>*@
 <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>

<script>
 $(function () {
     $("#tabs").tabs();
 });
 </script>

@{
   ViewBag.Title = "Edit";
 }
 <div class="editBanner">
 <div class="editor-label">
   @* @{
    string custCode = ViewBag.custCode;             
   }*@

   @* <h2>@Html.Label(custCode, custCode )</h2>*@
    <h2>@Html.Label(Model.Column_8, Model.Column_8 )</h2>
    </div>
    </div>
    <h3 style="font-size:20px">Edit</h3> 
    <br />  

 @*
 TAB 1 VEHICLE DATA SAVED TO VEHLIST 
 *@

  <div id="tabs">
<ul>
    <li><a href="#tabs-1">Vehicle</a></li>
    <li><a href="#tabs-2">Page 1</a></li>
    <li><a href="#tabs-3">Page 2</a></li>
</ul>
  <div id="tabs-1">
  @using (Ajax.BeginForm("Edit",null, new AjaxOptions
  {
    OnSuccess = "OnSuccessEditVehicle",
    OnFailure = "OnFailureEditVehicle",
    HttpMethod = "Post",
    UpdateTargetId = "tabs-1"
  }, new {id="EditVehicle"}))
{  
@Html.ValidationSummary(true)

<fieldset>
    <legend>VehList</legend>

        @Html.EditorForModel()

</fieldset>


 <div style="position:relative;left:750px"> 
           @Html.ActionLink("Back to List", "Index", new {custCode= ViewBag.custCode,    conName = ViewBag.connectionName}) |
       <input type="submit" value="Save" /></div>
}


@*
TAB 1 VEHICLE DATA SAVED TO VEHICLEDATA
*@

</div>
<div id="tabs-2">
    @{

        VehicleData vd =   ((Trakman_Portal_Administration.Controllers.VehicleController)this.ViewContext.Controller).EditVDPartial(Model.Column_0);
    }
        @Html.Partial("EditVDPartial", vd)

   @*  <div style="position:relative;left:750px"> 
           @Html.ActionLink("Back to List", "Index", new {custCode= ViewBag.custCode,   conName = ViewBag.connectionName}) |
       <input type="button" value="Save" onclick="submitVehicleDataForm()" /></div>*@

 </div>



@*
 TAB 3 VEHICLE DATA SAVED TO VEHICLE 
*@
<div id="tabs-3">
     @{

         vehicle v =    ((Trakman_Portal_Administration.Controllers.VehicleController)this.ViewContext.Controller).EditPartial(Model.Column_0);

     }
         @Html.Partial("EditPartial", v) 

    <div style="position:relative;left:750px"> 
           @Html.ActionLink("Back to List", "Index", new {custCode= ViewBag.custCode, conName = ViewBag.connectionName}) |
       <input type="submit" value="Save" /></div>

</div>



 </div>


<br />

控制器

 public ActionResult Edit(VehList vehlist)
    {

        tedb = new     trakman_Entities(System.Web.HttpContext.Current.Session["connection"].ToString());
        if (ModelState.IsValid)
        {
            vehlist.Column_8 =    System.Web.HttpContext.Current.Session["staticCustCode"].ToString();
            tedb.VehLists.Attach(vehlist);
            tedb.ObjectStateManager.ChangeObjectState(vehlist, System.Data.EntityState.Modified);
            tedb.SaveChanges();
            var cust = tedb.customers.First(c => c.code == vehlist.Column_8);
            //return RedirectToAction("Index", new { custCode = cust.code, conName = System.Web.HttpContext.Current.Session["connectionName"]});
        }

        ViewBag.Column_8 = new SelectList(tedb.customers, "code", "name", vehlist.Column_8);
        return View(vehlist);

    }
4

0 回答 0