我使用ASP.net,MVC5和C#构建一个房间预订网页表单,然后当用户提交表单时,它会将一封简单的html电子邮件通过电子邮件发送到电子邮件帐户。这一点工作得很好。
可预订的不同房间只列在彼此之下,旁边有一个复选框。
但是,如果选择了多个会议室(可能需要溢出房间或餐饮等),则仅通过电子邮件发送一个所选房间,而不是所有选定房间。我知道它正在这样做,因为if语句不会添加到数组。唯一的问题是,我不太了解阵列是如何工作的,所以我很难弄清楚如何做到这一点。
到目前为止我得到了什么:
Form.cshtml查看
<div class="form-group">
<h4>Please select a room:</h4>
</div>
<div class="form-group">
<div class="col-md-7">
@Html.CheckBoxFor(model => model.Room067)
- 0.67 - Small boardroom, can fit up to 10 people. Includes PC, Projector and speakers.
</div>
</div>
<div class="form-group">
<div class="col-md-7">
@Html.CheckBoxFor(model => model.Room073)
- 0.73 - Boardroom set up can fit to to 20 people. Includes PC, Projector and speakers.
</div>
</div>
<div class="form-group">
<div class="col-md-12">
@Html.CheckBoxFor(model => model.Room078)
- 0.78 - Leacture Theatre. Fixed tiered seating to accomodate 120 delegates. Room includes AV Equipment e.g. PC, Speakers, Projector and TV Monitors.
</div>
</div>
<div class="form-group">
<div class="col-md-12">
@Html.CheckBoxFor(model => model.Room079)
- 0.79 - Boardroom set up can fit up to 30 people. Can be set as a lecture room to accomodate 50 people. Includes PC, Projector and speakers.
</div>
</div>
<div class="form-group">
<div class="col-md-7">
@Html.CheckBoxFor(model => model.Room166)
- 1.66 - Small boardroom can fit up to 14 people. Includes PC, Projector and speakers.
</div>
</div>
有一个按钮,所以当单击按钮时,下面的代码片段会执行他们必须执行的操作,然后我在页面上的其余代码执行它需要执行的操作。
Form.cs Model
public Boolean Room067 { get; set; }
public Boolean Room073 { get; set; }
public Boolean Room078 { get; set; }
public Boolean Room079 { get; set; }
public Boolean Room166 { get; set; }
public Boolean Room063 { get; set; }
public Boolean Room072 { get; set; }
BookingFormController.cs
string SelectedRoom = "";
if (model.Room063 == true)
{
SelectedRoom = "Room 0.63";
}
else if (model.Room067 == true)
{
SelectedRoom = "Room 0.67";
}
else if (model.Room072 == true)
{
SelectedRoom = "Room 0.72";
}
else if (model.Room073 == true)
{
SelectedRoom = "Room 0.73";
}
else if (model.Room078 == true)
{
SelectedRoom = "Room 0.78";
}
else if (model.Room079 == true)
{
SelectedRoom = "Room 0.79";
}
else if (model.Room166 == true)
{
SelectedRoom = "Room 1.66";
}
我希望能够做的是使用IF Else法则来查看已选中的复选框,如果已选中,则添加房间号(即&#34; 1.66室和34号房间) ;)到SelctedRoom变量。
我知道我必须申报&#34; SelectedRoom&#34;变量作为数组,但我不知道在那之后该怎么做,或者甚至可以做。
帮助?大声笑,如果可以的话。