Reputation: 107
The Submit button is not calling the method in controller to save data, It is calling method use to load the page. My Code is as follows. I did try Html.BeginForm("ServiceEntryRegister","",FormMethod.Post)
public class ServiceEntryRegister
{
public List<ReceiptHeader> HEADER { get; set; }
public List<ReceiptDetail> DETAIL { get; set; }
public ReceiptHeader SingleHEADER { get; set; }
public ReceiptDetail SingleDETAIL { get; set; }
public List<Suburb> SUBURB { get; set; }
}
Controller:
public class ServiceEntryRegisterController : Controller
{
private AUTOEntities _er = new AUTOEntities();
private DateTime _Defaultdate = Convert.ToDateTime("01/01/1900 00:00:00");
public ActionResult Index(DateTime P_ServiceDate , String P_Registraion="x", String P_CustomerName="x")
{
var Model = new ServiceEntryRegister();
if(P_ServiceDate!=null || P_Registraion!=null || P_CustomerName!=null)
{
}
return View();
}
public ActionResult CreateNew()
{
CreateBagForLists();
var Model = new ServiceEntryRegister();
return View(Model);
}
[HttpPost]
private ActionResult CreateNew(ServiceEntryRegister RH,String save)
{
if (ModelState.IsValid)
{
int x = 0;
x++;
return View();
}
else
{
return View();
}
}
}
VIEW:
@model HIMA_AUTOWORKSHOP.Models.ServiceEntryRegister
@using (Html.BeginForm())
{
<table>
<td>
<table>
<th> </th>
<th></th>
<tr>
<td>Dated </td>
<td>Nil</td>
</tr>
<tr>
<td>Owner Name</td>
<td>@Html.TextBoxFor(o => o.SingleHEADER.OwnerName)</td>
</tr>
<tr>
<td>Mobile</td>
<td>@Html.TextBoxFor(w => w.SingleHEADER.Mobile, null, new { maxlength = 10, autocomplete = "on", style = "width:245px" })</td>
<tr>
<td></td>
<td><input name="submit" type="submit" id="submit" value="Save Request" /></td>
</tr>
</table>
</td>
</table>
}
@section Scripts {
@Scripts.Render("~/bundles/jqueryval")
}
Upvotes: 0
Views: 2693
Reputation: 11963
If the method is private then your post request will never invoke that method. But since you did not mark the parameterless method as HttpGet only that's why it gets invoked instead
Upvotes: 2