MVC 选项卡保存局部视图
MVC tabs saving partialview
我在每个选项卡中使用局部视图。我有 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?????
}
}
而不是使用 Html.BeginForm 使用 Html.AjaxForm
我在每个选项卡中使用局部视图。我有 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?????
}
}
而不是使用 Html.BeginForm 使用 Html.AjaxForm