如何获得用户在Asp.net MVC中选择的复选框的值?

问题描述 投票:0回答:1

我要打印用户选择的复选框的值。

View.cshtml

<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>

控制器

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;

}

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

请任何人能帮助您

asp.net asp.net-mvc asp.net-core asp.net-mvc-4 asp.net-web-api
1个回答
0
投票

如果要同时添加两个产品,请使用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);

如果您要使用单个项目,请使用array[index];

Body = "Dear " + name +" Your Order have been successfully Placed. Number of products placed are " + qty + "from " + qty + " Store" + checkResp[0];
© www.soinside.com 2019 - 2024. All rights reserved.