Thursday, 15 January 2015

asp.net mvc 4 - Getting formcollection data in the controller from view -



asp.net mvc 4 - Getting formcollection data in the controller from view -

pretty new mvc maybe doing wrong here .so have view

@scripts.render("~/bundles/jquery") @using (html.beginform()) { <div> <label>start date : </label> <input readonly="true" type="text" id="startdate" style="width:150px" /> <br /> <label>end date : </label> <input type="text" id="enddate" readonly="true" style="width:150px" /> <br /> <button>submit</button> <br /> </div> } <script type="text/javascript"> jquery(function () { jquery('#startdate').datepicker(); jquery('#enddate').datepicker(); }); </script>

and in action result in home controller have

public actionresult reports() { homecoming this.view(); } [httppost] public actionresult reports(formcollection form) { datetime start = convert.todatetime(form["startdate"].tostring()); datetime end = convert.todatetime(form["enddate"].tostring()); //something dates }

the issue formscollection empty .so no info coming through view controller.i have seen online examples working this.is there configuration missing or else gotta formscollection.

thanks

you have readonly on html input fields. these fields not posted server, design. seek removing readonly attribute , should work

edit: seems wrong on issue was. readonly fields passed server, disabled fields aren't. in case missing name attribute issue. reply have been right if had input fields disabled.

asp.net-mvc-4

No comments:

Post a Comment