将razor变量设置为下拉列表的值

时间:2016-04-19 19:56:22

标签: asp.net-mvc amazon-web-services razor

我在一个模态中有一个表单,它接收我的总ec2实例的列表。我正在尝试将第二个下拉调整为第一个下降值,以便第二个下拉列表查看实例的相对量。

<form action="/S3/AttachVolume/" method="POST">
    <div class="form-group">
        <p>Please double check the ids of your instance and volume</p>
             <label for="instanceId">InstanceId:</label>
             <select class="form-control text-center" name="instanceId" id="instances" style="margin: 0 auto">
             @for (var i = 0; i <= totalcount - 1; i++)
             {
                 foreach (var instances in Model.instances.Reservations[i].Instances)
                 {
                     <option>@instances.InstanceId</option>
                 }
             }
             </select>
             <label for="type">Volume Id:</label>
             <select class="form-control text-center" name="volumeId" id="volumeId" style="margin: 0 auto">
             @foreach (var volume in @*aboveinstance*@.BlockDeviceMappings)
             {
                 <option>@volume.DeviceName</option>
             }
         </select>
    </div>
    <div class="modal-footer">
         <button type="submit" class="btn btn-danger btn-lg" style="width: 100%;"><span class="glyphicon glyphicon-ok-sign"></span> Detach</button>
    </div>
</form>

是否可以将instanceId <select>的值存储在类似于var的变量中,以便我可以在第二个选择中循环它?

供参考,var instance包含以下数据enter image description here

很抱歉,如果这很明显我是.net和razor的新手,在使用aws sdk时很难找到资源

1 个答案:

答案 0 :(得分:0)

Razor在服务器端呈现View,并且不知道用户可以进行的任何客户端更改。

在加载页面之后发生的任何事情,例如选择更改,都必须通过javascript处理,如果使用像AngularJs这样的框架会让你的生活更轻松,那就更好了。

每次Select值更改时,您的Javascript函数都会调用服务,以获取重新填充其他Control所需的数据。