[英]ASP.NET Return View(“Index”); Return to same tab
I have a single asp.net page it contains a number of tabs and a datetime picker. 我有一个asp.net页面,它包含许多选项卡和日期时间选择器。
When the user selects a date from the datetime picker and clicks on the update button it does that it should do but it does not return the user to the same tab. 当用户从日期时间选择器中选择一个日期并单击更新按钮时,它会执行该操作,但它不会将用户返回到同一选项卡。
HTML Code HTML代码
<ul class='tabs'>
<li><a href='#tab1'>Production</a></li>
<li><a href='#tab2'>Page2</a></li>
<li><a href='#tab4'>Page3</a></li>
<li><a href='#tab6'>Page4</a></li>
</ul>
<div id='tab1'>
<hr />
<div class="ProductionDiv">
<label class="ProductionLabel">Production Data</label>
@{
using (Html.BeginForm("UpdateProductionData", "Home", FormMethod.Post))
{
<h3>Date :</h3> <input type="text" id="dp4" name="dp4"/>
<input type="submit" value="Update"/>
}
}
</div>
<div id='tab2'>
<hr />
<div class="ProductionDiv">
<label class="ProductionLabel">Production Data</label>
@{
using (Html.BeginForm("UpdateProductionData", "Home", FormMethod.Post))
{
<h3>Date :</h3> <input type="text" id="dp4" name="dp4"/>
<input type="submit" value="Update"/>
}
}
</div>
<div id='tab3'>
<hr />
<div class="ProductionDiv">
<label class="ProductionLabel">Production Data</label>
@{
using (Html.BeginForm("UpdateProductionData", "Home", FormMethod.Post))
{
<h3>Date :</h3> <input type="text" id="dp4" name="dp4"/>
<input type="submit" value="Update"/>
}
}
</div>
<div id='tab4'>
<hr />
<div class="ProductionDiv">
<label class="ProductionLabel">Production Data</label>
@{
using (Html.BeginForm("UpdateProductionData", "Home", FormMethod.Post))
{
<h3>Date :</h3> <input type="text" id="dp4" name="dp4"/>
<input type="submit" value="Update"/>
}
}
</div>
C# code I do what i need to do and return to the Index form is there any way to specify what tab to return too. C#代码我做我需要做的事情并返回索引表单是否有任何方法来指定返回哪个选项卡。 return View("Index"); return View(“索引”);
How about using hidden field + jquery, like this: 如何使用隐藏字段+ jquery,如下所示:
Update your ViewModel and add an int
property for example LastTabIndex, then Add a hidden field to your form: 更新ViewModel并添加一个int
属性,例如LastTabIndex,然后在表单中添加一个隐藏字段:
@Html.HiddenFor(m=>m.LastTabIndex)
and then use jquery : 然后使用jquery:
<script type="text/javascript">
$(function() {
$(".tabs").tabs({
create: function() {
var index = 0;
if (Modernizr.localstorage) {
if (localStorage.getItem("LastTabIndex") === null) {
localStorage.setItem("LastTabIndex", 0);
} else {
index = localStorage.getItem("LastTabIndex");
}
} else {
index = $('#LastTabIndex').val();
}
$(".tabs").tabs("option", "active", index);
},
activate: function() {
var sel = $('.tabs').tabs('option', 'active');
$("#LastTabIndex").val(sel);
if (Modernizr.localstorage) {
localStorage.setItem("LastTabIndex", sel);
}
}
});
});
</script>
EDIT: I've updated my code to use a hybrid solution (localstorage and if local storage is unsupported then use hidden field). 编辑:我已更新我的代码以使用混合解决方案(localstorage,如果本地存储不受支持,则使用隐藏字段)。
Hope this helps! 希望这可以帮助!
Regards, Uros 此致,Uros
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.