Hi nabilabolo,
Refer below sample.
Model
public class ItemModel
{
public string req_name { get; set; }
public string badge_num { get; set; }
public string line { get; set; }
public DateTime req_date { get; set; }
public int status { get; set; }
public string Requester_id { get; set; }
public int item_id { get; set; }
public string req_material { get; set; }
public Nullable<int> req_quantity { get; set; }
}
Controller
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
List<Materials> materials = new List<Materials>();
materials.Add(new Materials { ID = 1, Material = "Pencil" });
materials.Add(new Materials { ID = 2, Material = "A4 Paper" });
materials.Add(new Materials { ID = 3, Material = "Rubber" });
ViewBag.material = materials;
return View(new ItemModel());
}
public class Materials
{
public int ID { get; set; }
public string Material { get; set; }
}
public ActionResult AddPlatform()
{
return View();
}
[HttpPost]
public ActionResult AddPlatform(ItemModel Imodel)
{
TempData["Selected"] = "1";
TempData["Enabled"] = "0,1";
TempData["Disabled"] = "2";
try
{
}
catch (Exception)
{
}
return RedirectToAction("Index", "Home");
}
[HttpPost]
public ActionResult AddMateriaL(ItemModel Imodel)
{
RequesterEntities db = new RequesterEntities();
TempData["Selected"] = "2";
TempData["Enabled"] = "0,1,2";
try
{
}
catch (Exception)
{
}
return RedirectToAction("Index", "Home");
}
}
View
@model Enable_Disable_Tab_Button_Click_MVC.Models.ItemModel
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
<link rel="stylesheet" media="screen" href='https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css' />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.css" />
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.12.1/jquery-ui.min.js"></script>
<script type="text/javascript">
$(function () {
if ($('#hfSelected').val() != '') {
var enabled = [];
var disabled = [];
if ($('#hfEnabled').val() != '') {
enabled = $('#hfEnabled').val().split(',').map(Number);
}
if ($('#hfDisabled').val() != '') {
disabled = $('#hfDisabled').val().split(',').map(Number);
}
$("#tabs").tabs({ active: $('#hfSelected').val(), enabled: enabled, disabled: disabled });
} else {
$("#tabs").tabs({ disabled: [1, 2] });
}
$('#ddlMaterial').change(function () {
$('#req_material').val($(this).find('option:selected').text());
});
$('#ddlQuantity').change(function () {
$('#req_quantity').val($(this).find('option:selected').text());
});
});
</script>
</head>
<body>
<input type="hidden" value="@TempData["Selected"]" id="hfSelected" />
<input type="hidden" value="@TempData["Enabled"]" id="hfEnabled" />
<input type="hidden" value="@TempData["Disabled"]" id="hfDisabled" />
<div id="tabs">
<ul>
<li><a href="#tabs-1">Details</a></li>
<li><a href="#tabs-2">Material</a></li>
<li><a href="#tabs-3">Summary</a></li>
</ul>
<div id="tabs-1">
@using (Html.BeginForm("AddPlatform", "Home", FormMethod.Post))
{
<label for="name" class="mr-sm-2">Name:</label>
<span>@Html.EditorFor(model => model.req_name, new { htmlAttributes = new { @class = "form-control mr-sm-2", style = "width:800px" } })</span>
<br />
<label for="email" class="mr-sm-2">Badge Number:</label>
<span>@Html.EditorFor(model => model.badge_num, new { htmlAttributes = new { @class = "form-control mr-sm-2", style = "width:800px" } })</span>
<br />
<label for="phone" class="mr-sm-2">Line :</label>
<span>@Html.EditorFor(model => model.line, new { htmlAttributes = new { @class = "form-control mr-sm-2", style = "width:800px" } })</span>
<br /><br />
<div align="center">
<input id="btnSaveDetails" type="submit" value="Save" class="btn btn-primary" />
</div>
}
</div>
<div id="tabs-2">
@using (Html.BeginForm("AddMaterial", "Home", FormMethod.Post))
{
<div class="form-inline">
<label for="Material" class="mr-sm-2">Material:</label>
<select id="ddlMaterial">
<option value="0">Select</option>
@foreach (var item in ViewBag.material)
{
<option value='@item.ID'>@item.Material</option>
}
</select>
@Html.HiddenFor(m => m.req_material)
<span><label for="st" class="mr-sm-2">Quantity:</label></span>
<select id="ddlQuantity">
<option value="0">Select</option>
@{
for (int i = 1; i <= 100; i++)
{
<option value="@i">@i</option>
}
}
</select>
@Html.HiddenFor(m => m.req_quantity)
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input id="btnSaveMaterial" type="submit" value="Save" class="btn btn-primary" />
</div>
</div>
</div>
}
</div>
<div id="tabs-3">
Content for Tab 3 goes here.<br />
Lorem ipsum dolor sit amet, consectetuer adipiscing elit,
sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
</div>
</div>
</body>
</html>
Screenshot