Below is my view page. without <form> tag when I insert the values, its perfectly inserting. But when I insert with <form> tag the values not inserting, the debug point pointing to [HttpGet] instead of [HttpPost]. For validation purpose I have inserted the <form> tag. But it seem to be no use.. Tell me the solution….
@model CustMaster.Models.MyAccount
@using CustMaster.Models
@{
ViewBag.Title = "Customer Information";
}
<html>
<head>
<title>Customer Information</title>
<link href="../../style.css" rel="stylesheet">
</head>
<body>
<form action="" id="contact-form" class="form-horizontal">
@using (Html.BeginForm())
{
<table>
<tr>
<td><h3>User Information</h3></td>
</tr>
</table>
<table>
<tr>
<td>
<div class="control-group">
@Html.LabelFor(model => model.CustomerFirstName,
new { @class = "control-label" })
<div class="controls">
@Html.TextBoxFor(model => model.CustomerFirstName,
new { @class = "input-xlarge" })
</div>
</div>
</td>
<td>
<div class="control-group">
@Html.LabelFor(model => model.CustomerMiddleName,
new { @class = "control-label" })
<div class="controls">
@Html.TextBoxFor(model => model.CustomerMiddleName,
new { @class = "input-xlarge" })
</div>
</div>
</td>
</tr>
</table>
<button type="submit">Register</button>
}
@*</form>*@
<script type="text/javascript" src="../../assets/js/jquery-1.7.1.min.js"></script>
<script type="text/javascript" src="../../assets/js/jquery.validate.js"></script>
<script type="text/javascript" src="../../assets/js/jquery.validate.min.js"></script>
<script type="text/javascript" src="../../script.js"></script>
</body>
</html>
Below is my Controller
[HttpGet]
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(MyAccount myacc)
{
MyAccount ma = new MyAccount();
var objview = ma.GetCustInfo(myacc);
return View();
}
You cannot nest html forms => it results in invalid markup and undefined behavior. You will have to remove the outer
<form>. TheHtml.BeginFormalready generates a form tag. You seem to have commented the closing form tag but not the opening.And please format your code a little. It’s a complete mess to read:
Also please notice that I have fixed your script references by introducing url helpers instead of hardcoding the url to them.