问题描述
我建立一个内部页面,允许受信任的用户通过表单手动更改参数设置。这种设置的输入是(未知大小的)setupparameters的列表,每个值的特定列表。然后,用户可以选择全部或值的参数的子集。
I'm building an internal page that allows trusted users to change a parameter setup manually through a form. The inputs to this setup are a list of setupparameters (of unknown size), each with a specific list of values. The user can then select a value for all or a subset of the parameters.
我试图说明这与我对当前视图模型
I have attempted to illustrate this with my current model for the view
public class SetupModel
{
public List<SetupParameter> Parameters { get; set; }
}
public class SetupParameter
{
public string ParameterName { get; set; }
// list with text=paramvalue, value=paramvalueid
public SelectList ParameterValueList { get; set; }
// id of the selected parametervalue if any
public int? SelectedParameterValueID { get; set; }
}
我在渲染视图本目前的尝试:
My current attempt at rendering a view for this:
<% using (Html.BeginForm("Update", "Parameters") {%>
...
<% foreach( var parameter in Model.Parameters ) { %>
<div><%: parameter.ParameterName %></div>
<div><%: Html.DropDownListFor(x => parameter.SelectedParameterValueID, parameter.ParameterValueList, "Please select") %></div>
<% } %>
...
我的问题是我怎么能呈现一个观点,让我提交表单,并得到一个合理的理解模型回到我的表单操作,让我获得选择的参数值的列表。我不知道这里的最佳做法或技巧,所以我将AP preciate任何反馈我得到:)
My question is how can I render a view that allows me to submit the form and get a reasonably understandable model back to my form action that will allow me to obtain the list of selected parameter values. I'm not aware of the best practices or tricks here, so I will appreciate any feedback I get :)
推荐答案
您可以尝试使用的:
public ActionResult Submit(FormCollection formCollection)
{
//Iterate form collection to get fields
return View();
}
这篇关于ASP.NET MVC的形式处理未知数量的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!