c# - Populating global variable in razor view using JQuery (MVC) -


please see code below:

@{     var propertylist = new list<tuple<string, string>>(); }  <input type="text" data-id="@item.item1" class="form-control prop"/>  <a class="btn btn-default" id="run-report" href="@url.action("runreport", "reports", new {reportid = model.reportid, proplist = propertylist})"> run report</a>  <script>     $("#run-report").click(function () {         $(".prop").each(function () {             var currentprop = $(this).attr("data-id");             var currentpropval = (this).value;              @{                 propertylist.add(new tuple<string, string>("", ""));             }          });     });  </script> 

as can see above, have global variable called propertylist containing list of tuples, <string, string>.

i declare here because need use url.action download report direct browser controller action.

i have hit bit of wall when values text box. need add values jquery global list of tuples.

it doesn't can way.

any advice appreciated!

thanks

remember @{} code runs server-side, before gets browser. once has "rendered" in browser, it's if plain text , can't changed.

you can pass parameters building them in script, eg:

remove param url.action arguments

<input type="text" data-id="@item.item1" class="form-control prop"/> <a class="btn btn-default" id="run-report" href="@url.action("runreport", "reports", new {reportid = model.reportid})"> run report</a> 

add them via script

$("#run-report").click(function () {      var url = $(this).attr("href");      $(".prop").each(function () {         var currentprop = $(this).data("id");         var currentpropval = (this).value;          url += "?" + currentprop + "=" + currentpropval;     });      location.href = url; }); 

depending on format expected action, may need change how url built, shows principle.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -