Description:
I am using ASP.NET MVC 5
, jquery
(latest version).
I am building an application where i would be using jquery tabs
immensely.
I want to activate the current tab
(after Save->Reload
).
I am currently getting the current tab
value using a Tempdata .I have no issue in getting value using tempdata
. But i have to hard code
values.(If submit request comes from User
use '1'
, If Group
use '2'
,If Module
use '3'
).
Question:
How i can remove this hard coded approach.
I want to know what is the standard way to do this.
My Controller:
TempData["TabId"] =1
Jquery:
$(function () {
$("#tabs").tabs();
$("#tabs").tabs({
active: '@TempData["TabId"]'
});
});
function btn_Save_Module() {
$(".container").on("click", "#btn-Save-Module", function () {
$.ajax(
{
url: '@Url.Action("CreateEditModule")',
dataType: 'json',
data: $("#Form-Module").serialize(),
type: 'POST',
success: function (result) {
if (result)
alert("Successfully Saved");
else
alert("Save Failed");
location.reload(); //*see this line*
},
error: function (xhr) {
alert(xhr.statusText);
}
});
});
OK, if what I am looking at is a non-postback/ajax only save:
//Set active tab your .on("click" before the ajax call
var active = $( "#tabs" ).tabs( "option", "active" );
/// Then in your ajax success method
$("#tabs").tabs('select', active);
If there is a postback use a hidden field to store active and re-set upon postback
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.