asp.net - how to populate my API call URL with the model binder parameters -
i have following view, fields should sent part of api call:-
@using (html.beginform( "createprocess","rack", formmethod.post )) { <table width="650" bgcolor="#ffffff" cellpadding="5" cellspacing="0" style="border:1px #ccc solid" align="center"> <tr> <th colspan="4">save asset form</th> </tr> <tr> <td align="right" width="142">name</td> <td><input type="text" class="txt" name="assetname" style="width:160px;" /></td> <td width="142" align="right">asset type</td> <td><input type="text" class="txt" name="assettype" value="" style="width:160px;" /></td> </tr> <tr> <td align="right" width="142">product name</td> <td><input type="text" class="txt" name="productname" style="width:160px;" /></td> <td align="right" width="142">asset tag</td> <td><input type="text" class="txt" name="restag" style="width:160px;" /></td> </tr> <tr> <td colspan="4"> <table class="innertable" cellpadding="5" cellspacing="0" width="100%"> <tr> <td class="thd" colspan="4">resource info</td> </tr> <tr> <td align="right" width="142">asset serial number</td> <td><input type="text" class="txt" name="resslno" style="width:160px;" /></td> <td width="142" align="right">barcode</td> <td><input type="text" class="txt" name="barcode" value="" style="width:160px;" /></td> </tr> <tr> <td align="right" width="142">location</td> <td><input type="text" class="txt" name="location" style="width:160px;" /></td> <td width="142" align="right">purchase cost</td> <td><input type="text" class="txt" name="purchasecost" value="" style="width:160px;" /></td> </tr> <tr> <td class="thd" colspan="4">authentication details</td> </tr> <tr> <td align="right" width="142">username</td> <td><input type="text" class="txt" name="username" style="width:160px;" /></td> <td width="142" align="right">password</td> <td><input type="password" class="txt" name="password" value="" style="width:160px;" /></td> </tr> <tr> <td align="right" width="142">domain</td> <td><input type="text" class="txt" name="domain_name" style="width:160px;" /></td> <td align="right" width="142">authentication mode</td> <td><input type=radio name="logondomainname" value="local authentication" >local authentication <input type=radio name="logondomainname" value="ad_auth" >ad authentication</td> </tr> </table> </td> </tr> <tr> <td colspan="4" height="10"></td> </tr> <tr> <td align="center" colspan="4" class="footer"><input type="submit" name="operation" value="saveasset" class="btnsubmitact"></td> </tr> </table> }
my action method follow:-
[httppost] public actionresult createprocess(rack rack) { using (var client = new webclient()) { try { var query = httputility.parsequerystring(string.empty); var url = new uribuilder("http://localhost:8080/jw/web/json/process/create/" //notsure write hereā¦. ); url.query = query.tostring(); string json = client.downloadstring(url.tostring());
but how can construct api url inside action method, have model binder values parameters such as
http://localhost:8080/jw/web/json/process/create?parm1=&parm2=&etc....
you read them form
collection:
[httppost] public actionresult createprocess(rack rack) { using (var client = new webclient()) { client.headers[httprequestheader.accept] = "application/json"; var query = httputility.parsequerystring(string.empty); foreach (string key in this.request.form) { query[key] = this.request.form[key]; } var url = new uribuilder("http://localhost:8080/jw/web/json/process/create"); url.query = query.tostring(); try { string json = client.downloadstring(url.tostring()); } catch (webexception ex) { ... } } ... }
Comments
Post a Comment