Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get data from partial in form
    primarykey
    data
    text
    <p>I have ASP.NET MVC Form in popup with some controls and partial (data grid) with his own Model. here is popup:</p> <pre><code>&lt;div id="AddEditDialog" class="none"&gt; @using (Ajax.BeginForm("Save", "Templates", new AjaxOptions { InsertionMode = InsertionMode.Replace, UpdateTargetId = "AddEditPlaceHolder", OnSuccess = "OnSaveSuccess", HttpMethod = "Post" })) { &lt;div&gt; &lt;div id="AddEditPlaceHolder"&gt;&lt;/div&gt; &lt;div id="PopupButtons" class="btn-holder-centered"&gt; &lt;input type="submit" value="Save" name="SaveButton" /&gt; &lt;input type="button" value="Cancel" name="SaveCancelButton" id="CancelEditHandler" /&gt; &lt;/div&gt; &lt;/div&gt; } &lt;/div&gt; </code></pre> <p>here is form which I render in AddEditPlaceHolder via js:</p> <pre><code>@model TemplatesViewModel &lt;div class="form-field-plain overflow"&gt; &lt;div class="forRow narRow float-left"&gt; @Html.LabelFor(x =&gt; x.Revocable) @Html.CheckBoxFor(x =&gt; x.Revocable) &lt;/div&gt; &lt;/div&gt; &lt;div class="form-field-plain overflow"&gt; &lt;div class="forRow narRow float-left"&gt; @Html.LabelFor(x =&gt; x.HtmlTemplate) @Html.TextAreaFor(x =&gt; x.HtmlTemplate) &lt;/div&gt; &lt;/div&gt; @Html.Partial("_VariablesGridView", Model.Variables) </code></pre> <p>_VariablesGridView.cshtml:</p> <pre><code>@model List&lt;TemplateVariableViewModel&gt; &lt;table id="TemplateVariablesGrid"&gt; &lt;thead&gt; &lt;tr&gt; &lt;td&gt;Tag/Code&lt;/td&gt; &lt;td&gt;Prompt&lt;/td&gt; &lt;td&gt;Action&lt;/td&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; @foreach (var i in Model) { &lt;tr&gt; &lt;td&gt; @Html.TextBox("txtTag", @i.Tag, new {}) &lt;/td&gt; &lt;td&gt; @Html.TextBox("txtPrompt", @i.Prompt, new { }) &lt;/td&gt; &lt;td&gt; @Html.HiddenFor(x =&gt; x.First(s =&gt; s.Id == @i.Id).Id) &lt;label class="delete-variable"&gt;delete&lt;/label&gt; &lt;/td&gt; &lt;/tr&gt; } &lt;/tbody&gt; &lt;/table&gt; &lt;br /&gt; &lt;input type="button" name="btnAddTemplateVariable" value="add new variable"/&gt; &lt;br /&gt; </code></pre> <p>My problem is : in Controller 'save form' method public ActionResult Save(TemplateViewModel model)<br> my model contains all data from form but TemplateViewModel.Variables is empty</p> <p>Is there any way to fill it in there?</p> <p>Models:</p> <pre><code>public class TemplateViewModel { public int Id { get; set; } public string HtmlTemplate { get; set; } public List&lt;TemplateVariableViewModel&gt; Variables { get; set; } } public class TemplateVariableViewModel { public int Id { get; set; } public string Tag { get; set; } public string Prompt { get; set; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload