87,910
社区成员
发帖
与我相关
我的任务
分享
@using(Ajax.BeginForm("Save", "CashAdvance",new AjaxOptions
{
HttpMethod = "Post"
}))
{
@Html.AntiForgeryToken()
<p><a id="New" name="New" href="#">New</a></p>
<div class="table">
<table id="Table" name ="Table" class="table">
<thead>
<tr>
<th>
@Html.DisplayNameFor(m => m.Details.FirstOrDefault().description)
</th>
<th />
</tr>
</thead>
<tbody id="TableBody" name="TableBody">
</tbody>
</table>
</div>
<input class="btn-default" value="Save" type="submit" />
<input class="btn-default" value="Approval" type="button" />
<input id="CurrentDetailIndex" name="CurrentDetailIndex" type="hidden" value="@Model.Details.Count" />
}
@section Scripts
{
<script type="text/javascript">
$(function ()
{
$("#New").click(function () {
var index = $("#CurrentDetailIndex").val();
var content = {Index : index};
$.ajax({
url: '/controller/New',
data: content,
type: "GET",
data: content,
contentType: 'application/html; charset=utf-8',
success: function (data)
{
$("#TableBody").append(data);
$("#CurrentDetailIndex").val(parseInt(index) + 1);
$(".RemoveLink").on('click', function ()
{
var recordToDelete = $(this).attr("data-id");
if (recordToDelete != null) {
$("#" + recordToDelete).remove();
}
});
},
error: function (xhr) {
alert('error');
}
});
});
});
</script>
}
public ActionResult New(string index)
{
ViewBag.Index = index;
var model = new Model();
return PartialView("Detail", model);
}
<tr id="row-@Model.Identifer">
<td>
<div>
@Html.TextBox(string.Format("Details[{0}].description", (string)ViewBag.Index), Model.description)
@Html.ValidationMessage(string.Format("Details[{0}].description", (string)ViewBag.Index));
</div>
</td>
<td>
<a href="#" id="aaa" name="aaa" class="RemoveLink" data-id="row-@Model.Identifer"><span class="glyphicon glyphicon-remove" /></a>
</td>