1

I have a table and no form in one page that I am working with. Is there any way to persist certain values to that html without creating a form. I will not be submitting from this page in any specific way.

<!DOCTYPE html>
<html>
<head>
    <title>Show All Encounters</title>
</head>
<body>
<div class="content-wrapper clear-fix float-left"  style="height: 1px; padding: 10px;" id="list1">
    @{        
        Html.Hidden("popId", TempData["POPULATIONID"], new { id = "hidPopID" });
        Html.Hidden("popId", TempData["POPNAME"], new { id = "hidpnID" });
        Html.Hidden("popId", TempData["ROWNUM"], new { id = "hidrownumID" });
    }
 <table border="2" id="frTable" class="scroll"></table>  
 <div id='pager'></div>
 </div>
</body>
</html>
<script>
    function loadDialog(tag, event, target) {
        //debugger;
        .load($url)
      .dialog({
      ...
      , close: function (event, ui) {
            debugger;
            //if($url.contains)        
            var popId = $('#hidPopID').val();
            var rows = $('#hidrownumID').val();
            location.reload(true);
      }
        });

        $dialog.dialog('open');
    };
    </script>

that close event is inside of a jquery Modal dialog call btw, so the syntax is technically correct

6
  • What do you mean with "to persist certain values"? Commented Mar 11, 2013 at 15:22
  • I need certain values to be used in javascript functions I have on the page... It would be great for them to be global. One way I thought of doing this was to persist the values in hidden fields. Commented Mar 11, 2013 at 15:23
  • You need to use Ajax to do that and you don't need a form. Commented Mar 11, 2013 at 15:24
  • How do you do that with Ajax. From my understanding Ajax is way to get values of a server assynchronulsy without posting or getting persay. IE making an XHR request to the server. Commented Mar 11, 2013 at 15:25
  • your Javascript should be nested inside <script></script> tag mate. Commented Mar 11, 2013 at 15:30

1 Answer 1

2

You could persist the values wherever you want in the DOM but if you want to send them to the server you have a couple of options:

  • Form with hidden fields (you said you don't want this)
  • AJAX request that will harvest the values from the DOM
  • Anchor with the values in the query string

Or simply persist the values on the server. I guess that you are using some data store there which could be used.


UPDATE:

Now that you have shown your code it is clear why it is not working. You do not have any hidden fields (browse at the HTML source code in your browser to see that they are missing). You have just called the Html.Hidden helper on the server but you never outputted the result to the HTML

Now add your hidden fields correctly:

@Html.Hidden("popId", TempData["POPULATIONID"], new { id = "hidPopID" })
@Html.Hidden("popId", TempData["POPNAME"], new { id = "hidpnID" })
@Html.Hidden("popId", TempData["ROWNUM"], new { id = "hidrownumID" })
Sign up to request clarification or add additional context in comments.

4 Comments

Could you show examples of each? I have created hidden fields, but I am not able to pull them with my jquery code.
Why are you not able to pull them with your jQuery code? By the way showing your jQuery code might help us understanding the problem because right now we can only be shooting in the dark. Is there some specific code you are having problems with? I can of course show an example of each but I don't see how is this going to fix your current code.
I don't understand how that is different than what I did, except you didn't wrap all your Html.Hidden's in @{}? But Ill give it a shot
Look at the generated HTML in your browser and you will see how is it different :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.