asp.net mvc - HTTPPOST method not being called while using html.beginform -
i hope can me simple issue i'm having, can't figure out.
i using ajax calls in javascript submit forms no problem.
i'm trying use html.beginform helper, not hitting post method inside same controller using ajax call.
what need in order post method hit?
here controller code:
[httppost] //[validateantiforgerytoken] public async task<actionresult> create(category category) { if (modelstate.isvalid) { try { await db.addcategoryasync(category); } catch (system.exception ex) { throw ex; } } return view(category); }
here html:
@using (html.beginform()) { @*@html.antiforgerytoken()*@ @html.validationsummary() <div class="body-content"> <h4>category</h4> <hr /> <div class="form-group"> <div class="col-offset-1 col-lg-11 col-md-11 col-sm-11 col-xs-11"> @html.editorfor(model => model.description, new { htmlattributes = new { @class = "form-control", @placeholder = "description" } }) @html.validationmessagefor(model => model.description, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <button type="submit" id="btncategorycreate" class="btn btn-primary col-offset-2"><span class="glyphicon glyphicon-save"></span> create</button> </div> </div> }
here url in browser when click on submit button. inside home controller executing create method, during debugging, controller method never gets hit.
someone please , let me know simple mistake i'm overlooking...
http://localhost:1681/home/create?description=medical
edit
value of form tag ok.. issue is.. on form action tag reads: "saw 'form' start tag, there active 'form' element. nested forms not allowed. ignoring tag ().
that's why it's not posting.
i removed form tag in _layout.cshtml file, , it's posting because there 1 form tag specific page whereas when using calls via ajax, had form tag in _layout.cshtml file.
however, button off right of textbox instead of being underneath when had following ajax calls 1 form:
<form id="form1" class="form-horizontal" role="form">
i tried placing following on @html.beginform tag, button still right.
@using (html.beginform("create", "home", formmethod.post, new { htmlattributes = new { @class="form-horizontal", role="form"}}))
how can button underneath input box now?
@using (html.beginform("create", "home", formmethod.post, new { htmlattributes = new { @class="form-horizontal", role="form"}})) { @*@html.antiforgerytoken()*@ @html.validationsummary() <div class="body-content"> <h4>category</h4> <hr /> <div class="form-group"> <div class="col-offset-1 col-lg-11 col-md-11 col-sm-11 col-xs-11"> @html.editorfor(model => model.description, new { htmlattributes = new { @class = "form-control", @placeholder = "description" } }) @html.validationmessagefor(model => model.description, "", new { @class = "text-danger" }) </div> </div> <div class="form-group"> <button type="submit" id="btncategorycreate" class="btn btn-primary col-offset-2"><span class="glyphicon glyphicon-save"></span> create</button> </div> </div> }
do want call methode async or not?
try add more information html form:
@using (html.beginform("create", "home", formmethod.post))
if want use ajax , async use:
@using (ajax.beginform())
Comments
Post a Comment