我有 ASP.NET MVC窗體彈出窗口中有一些控件和部分(數據網格)與他自己的模型。 這裏彈出:如何從窗體中獲取部分數據
<div id="AddEditDialog" class="none">
@using (Ajax.BeginForm("Save", "Templates", new AjaxOptions
{
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "AddEditPlaceHolder",
OnSuccess = "OnSaveSuccess",
HttpMethod = "Post"
}))
{
<div>
<div id="AddEditPlaceHolder"></div>
<div id="PopupButtons" class="btn-holder-centered">
<input type="submit" value="Save" name="SaveButton" />
<input type="button" value="Cancel" name="SaveCancelButton" id="CancelEditHandler" />
</div>
</div>
}
</div>
這裏是形式,我在AddEditPlaceHolder通過JS渲染:
@model TemplatesViewModel
<div class="form-field-plain overflow">
<div class="forRow narRow float-left">
@Html.LabelFor(x => x.Revocable)
@Html.CheckBoxFor(x => x.Revocable)
</div>
</div>
<div class="form-field-plain overflow">
<div class="forRow narRow float-left">
@Html.LabelFor(x => x.HtmlTemplate)
@Html.TextAreaFor(x => x.HtmlTemplate)
</div>
</div>
@Html.Partial("_VariablesGridView", Model.Variables)
_VariablesGridView.cshtml:
@model List<TemplateVariableViewModel>
<table id="TemplateVariablesGrid">
<thead>
<tr>
<td>Tag/Code</td>
<td>Prompt</td>
<td>Action</td>
</tr>
</thead>
<tbody>
@foreach (var i in Model)
{
<tr>
<td>
@Html.TextBox("txtTag", @i.Tag, new {})
</td>
<td>
@Html.TextBox("txtPrompt", @i.Prompt, new { })
</td>
<td>
@Html.HiddenFor(x => x.First(s => s.Id == @i.Id).Id)
<label class="delete-variable">delete</label>
</td>
</tr>
}
</tbody>
</table>
<br />
<input type="button" name="btnAddTemplateVariable" value="add new variable"/>
<br />
我的問題是:在 控制器「保存窗體'方法public ActionResult保存(TemplateViewModel模型)
我的模型包含所有數據f ROM形式,但TemplateViewModel.Variables是空的
有沒有什麼方法可以填充它呢?
型號:
public class TemplateViewModel
{
public int Id { get; set; }
public string HtmlTemplate { get; set; }
public List<TemplateVariableViewModel> Variables { get; set; }
}
public class TemplateVariableViewModel
{
public int Id { get; set; }
public string Tag { get; set; }
public string Prompt { get; set; }
}
您需要發佈從_ConsentVariablesGridView.cshtml – 2013-04-10 14:42:22
標記,我只是將它加入 – 2013-04-10 14:48:00