我在每个标签中使用偏见。我有3个标签。
选择标签后,如何在局部视图中提交表单并在发布到控制器后保留在同一选项卡上?我只想在保存后刷新部分视图,希望不是整个页面。
订单控制器
public ActionResult order()
{
return View();
}
order.cshtml
<div id="tabs">
<ul class="nav nav-tabs">
<li class="active"><a href="#tabs-1">General</a></li>
<li><a href="#tabs-2">Item</a></li>
<li><a href="#tabs-3">Total</a></li>
</ul>
<div id="tabs-1">
@{Html.RenderPartial("_Partial_General_Tab");}
</div>
<div id="tabs-2">
@{Html.RenderPartial("_Partial_Item_Tab");}
</div>
<div id="tabs-3">
Content for Tab 3 goes here.<br />
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$("#tabs").tabs();
});
</script>
_Partial_General_Tab.cshtml
@model Mvc5.Models.ORDERMetadata
@using (Html.BeginForm("Edit", "Order"))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
// Set New Order Number
@Html.HiddenFor(model => model.Order_Number, new { @Value = ordernumber })
@Html.TextBoxFor(model => model.Order_Date})
<button id="editorder" type="submit">Save</button>
}
_Partial_Item_Tab.cshtml
@model Mvc5.Models.ORDER_DETAILSMetadata
@using (Html.BeginForm("Item", "Order"))
{
@Html.AntiForgeryToken()
@Html.ValidationSummary(true)
// Set New Order Number
@Html.HiddenFor(model => model.Order_Number, new { @Value = ordernumber })
@Html.TextBoxFor(model => model.Item})
<button id="edititem" type="submit">Save</button>
}
编辑控制器
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Edit(ORDERMetadata model)
{
try
{
// update order
return RedirectToAction("order"); //<----- Is this correct redirecting?????
}
}
项目控制器
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Item(ORDER_DETAILSMetadata model)
{
try
{
// update order
return RedirectToAction("order"); //<----- Is this correct redirecting, do I need to pass what tab it is on?????
}
}
答案 0 :(得分:0)
而不是使用Html.BeginForm使用Html.AjaxForm