Вопрос

I am using the partial view with the ajax.beginform. In that partial view page, i have the following markup EDIT

<%
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>

and in the the controller, i have this model for the representation of the data

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

EDIT

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

when i post the data these parametername and parameter values are not at all bound to the list of objects. How do i do this. i am using microsoft ajax and want to do this without using other plugings. Kindly suggest the right way.

EDIT

This is the data in the header taken from 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
Это было полезно?

Решение

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)
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top