asp.net mvc - MVC: Send parameters to Action in Controller with Bootstrap button -
view:
@using (html.beginform("updatematerial", "mycontroller", formmethod.post, model.materialid)) { @html.antiforgerytoken() <input type="submit" class="btn btn-primary custom" value="derivate material" /> }
controller:
[httppost] public actionresult updatematerial(int? matid) { if (matid == null) { return new httpstatuscoderesult(httpstatuscode.badrequest); } //do here }
the id send null. how change this?
your model.materialid
should form element:
@using (html.beginform("updatematerial", "mycontroller", formmethod.post)) { @html.hiddenfor(model => model.materialid) @html.antiforgerytoken() <input type="submit" class="btn btn-primary custom" value="derivate material" /> }
additionally, should change action definition , make accept type of model, instead of int?
:
[httppost] public actionresult updatematerial(mymodeltype model) { if (model.matid == null) { return new httpstatuscoderesult(httpstatuscode.badrequest); } //do here }
Comments
Post a Comment