jquery - How to use dynamically added hidden input field to form in controller action in asp.net mvc 3? -


i have tried in following way .this fine adds hidden input form dynamically .but how hidden input field used in controller action further work rendering dynamically added image in browser.

jquery append method :

<script type="text/javascript">        var alts = "";        var n = 65;         $(document).ready(function () {            $(function () {                $("#selectable_images img").click(function () {                    var $this = $(this);                    //                      alts = $(this).attr("alt");                    // alert(alts);                    if ($this.hasclass('selected')) {                        $("#" + this.rel).attr('checked', false);                        $this.removeclass('selected');                        // $("#postform").remove("");                        //$("input[type='hidden']").remove();                         //$('input[type="hidden"][value="' + alts + '"]').remove();                        alts = $(this).attr("alt");                         var ref = "#";                        ref += alts.tostring();                        alert(ref);                        $(ref).remove();                     } else {                        $("#" + this.rel).attr('checked', true);                        $this.addclass('selected');                        alts = $(this).attr("alt");                        alert(alts);                        charpos++;                         $("#postform").append("<input type='hidden' id='" + alts.tostring() + "' value='" + n.tostring() + "'/>");                        n++;                    }                })            })        }); </script> 

image tag:

<div class="selected" id="selectable_images">     <table>         <tr>             <td>                 <img src="../../images/wi0096-48.gif"  alt="image1" class="conversation_img"/>             </td>             <td>                 <img src="../../images/down.png"  alt ="image1"/>             </td>             <td>                 <img src="../../images/wi0054-48.gif" alt="image2" />             </td>             <td>                 <img src="../../images/photo-icon.png" alt="image3" />             </td>  </div> 

form:

@using (html.beginform("mapicon","test", formmethod.post,new { id = "postform" })) {        <input type="submit" value="match"/> } 

you need give hidden input name attribute value. name attribute used identify form post values on server side.

so assuming give value (when create javascript) like: name="myhiddeninput"

you can access within controller action using following:

string myhiddeninput = request.form["myhiddeninput"]; 

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -