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");
        }

データを投稿すると、これらのパラメーター名とパラメーター値はオブジェクトのリストにまったくバインドされません。どうすればこれを行うことができますか。私はMicrosoftajaxを使用しており、他のプラグを使用せずにこれを実行したいと考えています。正しい方法を提案してください。

編集

これは、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

私が理解していることは、あなたはマスターディテール構造を持っていて、それをコントローラーに受け取りたいと思っているということです。その場合。次に、詳細部分に可変長詳細部分があるか、固定長詳細部分があるかの2つの可能性があります。可変長と固定長については、こちらの投稿をフォローしてください。固定長の場合は、こちらもフォローできます。

次の署名でモデルを受け取ります

public ActionResult ManageDataSources(DataSourceViewModel dsvm)

formcollectionさらに、actionresultのパラメータを確認することもできます

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