【发布时间】:2018-02-05 07:02:55
【问题描述】:
查看:
@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 调用并从那里返回响应数据(可能使用部分视图或 AJAXsuccess可以append选项元素用于第二个下拉菜单)。跨度>
标签: c# html asp.net-mvc asp.net-mvc-5