I have a Razor MVC 5 form pushing data to a sql database. When i hit submit the form just reloads and the form values are retained. Checking in the database i see that no values are committed.
I have the POST version of the ActionResult already decorated with [HttpPost]. Additionally in the view i have explicitly specified FormMethod.Post.
This is my Bank.cshtml :
model MY_SYSTEM.Models.Employee.Registration
@{
ViewBag.Title = "Bank";
Layout = "~/Views/Shared/_LayoutPageh.cshtml";
}
@using (Html.BeginForm("Bank", "Employee", FormMethod.Post, new { @class = "form-horizontal" }))
{
@Html.AntiForgeryToken()
<div class="main-content-inner">
<div class="page-content">
<div class="page-header">
<h1>Employee Bank Detail</h1>
</div>
<div class="error">@ViewBag.ErrorMessage</div>
<div class="row">
<div class="col-xs-12">
<div>
<div class="user-profile row">
<div class="col-sm-offset-1 col-sm-8">
<form class="form-horizontal">
<div class="tabbable">
<div class="tab-content profile-edit-tab-content">
<div id="edit" class="tab-pane in active">
<div class="row">
<div class="col-xs-12 col-sm-8">
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for="form-field-facebook">Bank</label>
<div class="col-sm-9">
<span class="input-icon">
@*@Html.DropDownList("BankId", new SelectList(Model.Banks, "BankId", "BankName"),"-----Select Category-----")*@
@Html.DropDownListFor(m => m.BankId, Model.Banks, "Please Select", htmlAttributes: new { @class = "form-control" })
@Html.ValidationMessageFor(model => model.BankId, "", new { @class = "text-danger" })
class="ace-icon fa fa-bank blue">
</span>
</div>
</div>
<div class="space-4"></div>
<div class="form-group">
<label class="col-sm-3 control-label no-padding-right" for="form-field-facebook">Account Name</label>
<div class="col-sm-9">
<span class="input-icon">
@Html.EditorFor(model => model.AccountName, new { htmlAttributes = new { @class = "form-control", @placeholder = "" } })
@Html.ValidationMessageFor(model => model.AccountName, "", new { @class = "text-danger" })
^__i class="ace-icon fa fa-user blue">
</span>
</div>
</div>
<div class="space-4"></div>
<div class="">
<button type="submit" class="btn btn-sm btn-success">
Submit
^__i class="ace-icon fa fa-arrow-right icon-on-right bigger-110">
</button>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
}
My ActionResult methods are as below:
//GET
public ActionResult Bank ()
{
Models.Employee.Registration bank = new Models.Employee.Registration();
bank.Banks = PopulateBank();
bank.SortCodes = PopulateSortCode();
bank.AccountTypes = PopulateAccountType();
return View(bank);
}
//POST
[HttpPost]
public ActionResult Bank(Models.Employee.Registration bank)
{
if (!ModelState.IsValid)
{
bank.Banks = PopulateBank();
bank.SortCodes = PopulateSortCode();
bank.AccountTypes = PopulateAccountType();
return View(bank);
}
try
{ ... cmd.ExecuteNonQuery();
}
return RedirectToAction("Index");
}
catch (Exception)
{
bank.Banks = PopulateBank();
bank.SortCodes = PopulateSortCode();
bank.AccountTypes = PopulateAccountType();
ViewBag.ErrorMessage = Helpers.Messages.GENERAL_ERROR;
return View(bank);
}
}
What I have tried:
When i hit submit no error is being returned, it just reloads. In the Chrome Developer Tools -- Network i dont see anything pushed in data. The traffic just relates to JS, Css etc. I have also checked the Console and no meaningful messages are returned except the following (which seems not really significant, unless im missing its significance) :
Uncaught Error: Invalid dimensions for plot, width = null, height = null
at b.resize (jquery.flot.min.js:8)
at new b (jquery.flot.min.js:7)
at t (jquery.flot.min.js:7)
at new c (jquery.flot.min.js:8)
at Function.a.plot (jquery.flot.min.js:8)
at drawPieChart (mihr20:615)
at HTMLDocument.<anonymous> (mihr20:643)
at j (jquery-2.1.4.min.js:2)
at Object.fireWith [as resolveWith] (jquery-2.1.4.min.js:2)
at Function.ready (jquery-2.1.4.min.js:2)