Hi anjali600,
Please refer the below sample code.
Controller
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(string name)
{
return View();
}
}
View
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
@using (Html.BeginForm("Index", "Home", FormMethod.Post))
{
@Html.Hidden("Name")
<input type="submit" value="Set Name" onclick="return SetName();" />
<br />
<input type="submit" value="Save" />
<script type="text/javascript">
function SetName() {
document.getElementById("Name").value = "Mudassar Khan";
return false;
}
</script>
}
</body>
</html>
Screenshot