1

please I have a problem with the parameters of an action. Can someone help me? I'll explain:

I have an action "Etiquette (string nom_pharm, int numBon, int nbColis)" in the "Etiquetage" controller. In the view I have two input text for numBon and nbColis, I try to get them back to pass them in parameter but always the second one indicates that it is null, I use this line:

<input type="button" value="Ok" onclick="window.location = '@Url.Action("Etiquette", "Etiquetage",new { nom_pharm = @Model.PharmacieNom, numBon = " ", nbColis = " " })'+parseInt(document.getElementById('in').value), +parseInt(document.getElementById('bon').value)" />

Do you have an idea of the correct syntax?

2
  • In your question please show types for Etiquette method parameters. You're assigning empty string to numBon on that code. What do you expect to get? Commented Oct 15, 2020 at 23:49
  • Yes sorry , Etiquette (string nom_pharm,int numBon, int nbColis) Commented Oct 16, 2020 at 8:24

1 Answer 1

1

The relative url you need is /Etiquetage/Etiquette?non_pharm={value of in}&numBon={value of bon}&nbColis={value of in} but your code is generating this /Etiquetage/Etiquette?non_pharm={value}&numBon= &nbColis= {value of in}{value of bon}.

Your approach is a bit strange. A more conventional approach would be to use a form with a POST rather than a GET. Assumming you have a good reason for using javascript here for sending a GET request this code should work.

<input type="button"
   value="Ok"
   onclick="window.location = '@Url.Action("Etiquette", "Etiquetage")[email protected]&numBon='
                                        + document.getElementById('bon').value + '&nbColis='
                                        + document.getElementById('in').value" />

Note I have assumed that 'bon' goes with numBon and 'in' goes with nbColis. Because you are creating a string the parseInts are not needed.

Sign up to request clarification or add additional context in comments.

Comments

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.