@using (Html.BeginForm("Index", "APIController",FormMethod.Post))
{
<select id="Segmentation" name="Segmentation">
@foreach (var item in Model.listofSegments)
{
<option>@item</option>
}
</select>
<input type="submit" value="Send" />
}
型號:
public class SegmentRepository
{
public List<String> GetSegmentation()
{
//I have the values in this
}
}
控制器:
public class APIController : Controller
{
public ActionResult Index(FormCollection formCollection)
{
dynamic mymodel = new ExpandoObject();
SegmentRepository segment = new SegmentRepository();
mymodel.listofSegments = segment.GetSegmentation();
String roleValue1 = formCollection["Segmentation"];
return View(mymodel);
}
}
我不能獲取roleValue1
中的選擇選項值。
我想取roleValue1
的值,並用它來觸發我認爲的另一個下拉菜單。
有你想使用級聯HTML'select'?如果我的猜測是正確的,請考慮使用客戶端JS觸發AJAX調用控制器動作並從那裏返回響應數據(可能使用部分視圖或AJAX「成功」,它可以爲第二個下拉菜單添加選項元素)。 –