0

我正在使用带有 ajax.beginform 的局部视图。在该部分视图页面中,我有以下标记 编辑

<%
using (Ajax.BeginForm("ManageDataSources", "DataSources", saveAjaxOptions))
{
%>....
<td>
                <%: Html.Hidden("DataSource_Id", dataSource.Id, new { @class = "DataSource_Id" })%>
                <%: Html.TextBox("DataSource_Name", dataSource.Name, new { @class = "DataSource_Name" })%>
            </td>
 <tr class="queryParameters" style="display: block">

        <td colspan="2" align="center">

            <input id="Text1" name="parametername" type="text" />

            <input id="Text2" name="parametervalue" type="text" />

            <input id="Text3" name="parametername" type="text" />

            <input id="Text4" name="parametervalue" type="text" />

            <input id="Text5" name="parametername" type="text" />

            <input id="Text6" name="parametervalue" type="text" />

            <input id="Text7" name="parametername" type="text" />

            <input id="Text8" name="parametervalue" type="text" />

            <input id="Text9" name="parametername" type="text" />

            <input id="Text10" name="parametervalue" type="text" />

        </td>

    </tr>

在控制器中,我有这个模型来表示数据

public class DataSourceViewModel
{
    public string DataSource_Id { get; set; }
    public string DataSource_Name { get; set; }
    public List<SCParams> parameters { get; set; }
}

public class SCParams
{
    public string parametername { get; set; }
    public string parametervalue { get; set; }
}

编辑

public ActionResult ManageDataSources(DataSourceViewModel dsvm)
        {
            return PartialView("ManageDataSources");
        }

当我发布数据时,这些参数名和参数值根本没有绑定到对象列表。我该怎么做呢。我正在使用 microsoft ajax 并希望在不使用其他插件的情况下做到这一点。请建议正确的方法。

编辑

这是从 chrome 获取的标头中的数据

DataSource_Id:
DataSource_Name:Name
parametername:a
parametervalue:1
parametername:q
parametervalue:2
parametername:z
parametervalue:3
parametername:s
parametervalue:4
parametername:w
parametervalue:5
x:15
y:12
4

1 回答 1

1

What I understand you have master detail structure and you want to receive it controller. if that is the case. then there are two possibilities either your detail portion has variable length detail portion or fixed length detail portion. You may follow the post here for variable length as well as fixed length. For Fixed length you may also follow here.

You will receive the model in following signature

public ActionResult ManageDataSources(DataSourceViewModel dsvm)

moreover you may also check formcollection parameter for actionresult

       [HttpPost]
        public ActionResult MyAction(FormCollection collection)
于 2012-01-13T19:34:13.703 回答