asp.net - Error in form collection MVC 4 -
i'm trying add textbox values db using formcollection class every time giving 1 textbox value not other textboxes values. i'm sharing have done far. please guide me
textbox in view:
<input type="text" name="abcd" autocomplete="off" id="partnumber0" style="width:130px;" /> <input type="text" name="abcd" autocomplete="off" id="partnumber1" style="width:130px;" /> <input type="text" name="abcd" autocomplete="off" id="partnumber2" style="width:130px;" /> <input type="text" name="abcd" autocomplete="off" id="partnumber3" style="width:130px;" /> <input type="text" name="abcd" autocomplete="off" id="partnumber4" style="width:130px;" /> <input type="text" name="abcd" autocomplete="off" id="partnumber5" style="width:130px;" />
actionmethod:
public async task<actionresult> create(formcollection values) { var abc = values["abcd"].tostring(); var getid = await db.parts.where(c =>c.partnumber==abc).firstordefaultasync(); }
it saving first textbox name "abcd" value db, want textboxes values in db, please guide me
this because u r using same name form collection class reads name of control use following code , u different value different name of textbox
@using (@html.beginform("demo", "admin")) { <input type="text" name="partnumber0" autocomplete="off" id="partnumber0" style="width:130px;" /> <input type="text" name="partnumber1" autocomplete="off" id="partnumber1" style="width:130px;" /> <input type="text" name="partnumber2" autocomplete="off" id="partnumber2" style="width:130px;" /> <input type="text" name="partnumber3" autocomplete="off" id="partnumber3" style="width:130px;" /> <input type="text" name="partnumber4" autocomplete="off" id="partnumber4" style="width:130px;" /> <input type="text" name="partnumber5" autocomplete="off" id="partnumber5" style="width:130px;" /> <input type="submit" value="click" /> }
thank you
Comments
Post a Comment