0
<div class="col-md-3 ingname">
  <input class="form-control ingredient-name" placeholder="Ingredient Name" id="ingredientName[]" name="ingredientName[]" required />
</div>
<div class="col-md-3 ingqty">
  <input class="form-control ingredient-quantity" placeholder="Quantity" type="number" min="0" id="ingredientQty[]" name="ingredientQty[]" required/>
</div>

how to pass these inputs to a controller

is this correct?

public ActionResult UploadRecipe(Recipe recipe, string ingcount, string moodid, string[] ingredientName, int[] ingredientQty, string[] ingredientUnit) {

1 Answer 1

0

Apparently, you can only bind these data type in html input tags.

By removing [] from the input name you can get values in the controller. But you can't get a array of string or int in controller directly. What you can do is convert array to string with JSON.stringify(arr) and bind it with text input, then convert it back to array in your controller.

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.