javascript - Is it possible to construct a link, navigate to it and print the response in C# programmatically? How? -


i have webpage written in c#/razor. printing values database on page :

<div style="min-height: 150px; font-size: 1.25em">     <div style="margin-bottom: .5em">         <table>             <thead>                 <tr>                     <th>name</th>                     <th>branch</th>                     <th>phone no.</th>                     <th>extension</th>                     <th>email</th>                 </tr>             </thead>             <tbody>                 @foreach (var prod in model)                 {                     <tr>                         <td>@prod.fullname</td>                         <td>@prod.branch</td>                         <td>@prod.phoneno</td>                         <td>@prod.extension</td>                         <td>@prod.email</td>                         @if (user.isinrole(@"admins") || user.identity.name == prod.domainac)                         {                             <td><a href="/home/edit/@prod.id"  style="color: blue;">edit</a></td>                         }                         else                         {                             <td>user => @user.tostring()</td>                            }                         <td>                             <input type="checkbox" name="message" value="@prod.phoneno">message<br>                         </td>                     </tr>                 }             </tbody>         </table>     </div> </div> 

this works fine display info. small bit more difficult.

below this, have form username, password , message. using form, have behaviour on submit, take values in input boxes of form , above c#, construct link, navigate link , print response of server

so have :

@{if (ispost)   {      //handle , print response   }   else   {     <form method="post" action="">         username:<br />         <input type="text" name="u" /><br />         password<br />         <input type="text" name="p" /><br />         <br />         password<br />         <textarea name="m" cols="25" rows="5">         enter comments here...         </textarea><br>         <br />         <input type="submit" value="submit" class="submit" />//when clicked, construct url , navigate it.     </form>    } } 

the url want construct form :

http://webaddress.com/web/d.php?u=<username entered user>&p=<password entered user>&s=<list of phone numbers c# above checkbox selected, comma separated>&m=<comment submitted user> 

so, if name "john", password "password1", comment "test" , have selected 1 checkbox user phone number "12345678", url navigate :

http://webaddress.com/web/d.php?u=john&p=password1&s=12345678&m=test 

ideally print response of webpage in <div> while still on same parent web page rather going new 1 if possible.

i have no idea begin this, how or if possible. can me please ?

update :

trying jquery not alert me cannot debug :

    <script>         $("#thebutton").click(function() {             var form = $(document.getelementbyid('formid'));             var urltoconstruct = 'http://webaddress.com/web/d.php';             urltoconstruct += '?u=' + form.find('#u').val();             urltoconstruct += '&p=' + form.find('#p').val();             ('#employeetable tbody tr').has(':checkbox:checked').find('td:eq(2)').each(function() {                 urltoconstruct.append($(this).text());                 alert(urltoconstruct);             })         });  </script> 

$("#submitbuttonid").click(function() {     var form = $(document.getelementbyid('formid');     var urltoconstruct = 'http://webaddress.com/web/d.php';     urltoconstruct += '?u=' + form.find('#idofinputcontrol1').val();     urltoconstruct += '&p=' + form.find('#idofinputcontrol2').val();     form.submit(); }); 

this example uses jquery, javascript library (jquery.com), i'm using getelementbyid find form, faster native jquery() selector. example assumes controls inside form (but if not wouldn't train smash, cant use (jquery obj).find).

.val() gets value, , should work checkboxes too, if doesn't, quick google search getting values checkboxes using jquery return loads of results.

p.s. i've written code freehand, not checked in browser make sure correct.

update... answer follow question...

if using mvc (assumed using razor), inside controller can use request.params["urlparameter"] or request.form["controlid"] access you've received browser. once you've got values, should place them inside 'viewbag' (viewbag.yourvariablehere="val") them accessible in view via @viewbag.yourvariablehere, or can include required data in model can accessed in view


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

node.js - Node - Passport Auth - Authed Post Route hangs on form submission -

Does Firefox offer AppleScript support to get URL of windows? -