简体   繁体   中英

How pass js value to Html.BeginForm in razor

How can i passe javascript value to Html.BeginForm in razor ?

I have tow values :

var listeTiersSelected = JSON.stringify($("#GetTiersAttached").bootstrapTable('getSelections'));
var listeSipSelected = JSON.stringify($("#GetSpiAttached").bootstrapTable('getSelections'));

And i whant to passe this values to:

@using (Html.BeginForm("AddUser", "User", new {..........}))
        {

Html.BeginForm is server code which is executed before loading the page, when your page is loaded it will be replaced by HTML.

You haven't posted your complete code, but, usually, js code executes after client page is loaded. This means that probably your listeTiersSelected and listeSipSelected variables get their values AFTER Html.BeginForm has been executed.

If this is the case, what you should do is to apply whatever changes or effects you want to get into the form through client code.

if your script execute after html loading, add to form hidden input

Html.Hidden("GetTiersAttached", "Value", new { @id = "GetTiersAttached" })
Html.Hidden("GetSpiAttached", "Value", new { @id = "GetSpiAttached" })

and update value of this hidden field in your script

$("#GetTiersAttached").val(JSON.stringify($("#GetTiersAttached").bootstrapTable('getSelections')));
$("#GetSpiAttached").val(JSON.stringify($("#GetSpiAttached").bootstrapTable('getSelections')));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM