ASP.NET MVC2に部分的なビューとMicrosoftAjaxを使用したコレクションの投稿

StackOverflow https://stackoverflow.com/questions/8851028

質問

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
役に立ちましたか?

解決

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

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

public ActionResult ManageDataSources(DataSourceViewModel dsvm)

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

       [HttpPost]
        public ActionResult MyAction(FormCollection collection)
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top