1

I want to print the value /values of checkbox selected by the user. For that purpose I have taken a String[] checkResp.

For Example: If checkResp[0] then select value at index 0.

View

<input type="checkbox" id="vehicle1" name="checkResp" value="Bike">
<label for="vehicle1"> I have a bike</label><br>
<input type="checkbox" id="vehicle2" name="checkResp" value="Car">
<label for="vehicle2"> I have a car</label><br>
<input type="checkbox" id="vehicle3" name="checkResp" value="Boat">
<label for="vehicle3"> I have a boat</label><br><br>

Controller

public ViewResult Form(string receiveremail, string subject, string message,string name, int qty, string[] checkResp) 
{
        Body = "Dear " + name +" Your Order have been successfully Placed. Number of products placed are " + qty + "from " + qty + " Store" + checkResp;
}

ScreenShot is attached herewith:

It displays the values like this i want value at index 0

Please if any one can help

2
  • you want to include Bike and Boat in the body text? Commented Mar 26, 2020 at 13:23
  • yes I want Bike and Boat to display after Store in Body section Commented Mar 26, 2020 at 13:37

1 Answer 1

1

If you want to add both products use String.Join(delimiter,array);

Body = "Dear " + name +" Your Order have been successfully Placed. Number of products placed are " + qty + "from " + qty + " Store" + String.Join(",",checkResp);

If you want a single item use array[index];

Body = "Dear " + name +" Your Order have been successfully Placed. Number of products placed are " + qty + "from " + qty + " Store" + checkResp[0];
Sign up to request clarification or add additional context in comments.

2 Comments

but when I add checkResp[0] wouldnt it take the value at index 0?
@Samavi use the first option in my answer then, it's String.Join(",",checkResp)

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.