-1
我从CSHTML文件在客户端使用jQuery或JavaScript与内容从模型动态添加行
<div id="trows" class="table-responsive">
<table class="table table-bordered" id="myTable">
</div>
和添加按钮事件中剪断下面的代码添加行我试图为以下: -
var itemRSelected = $("#SelectedteRId option:selected").text();
var itemNSelected = $("#SelectedName option:selected").text();
debugger;
//all ok till above. I verified in debuggger
//but I am not able to add these values along with the Model rows to the table using below code. Any help? clue to fix the issue?
@{var i = 0;}
@foreach (MyNameSpace.Models.MyClassObj p in Model.myClassList)
{
if(itemRSelected == p.RowId && itemNSelected == p.NamePix) {
var row = "<tr><td>" + @(p.RowId) + "</td><td>" + @(p.NamePix) +
"</td><td>" + @(p.Mi) + "</td><td>" + @(p.Name) +
"</td><td>" + @(p.ExtraDate) +
"</td><td><a class='btn btn-danger btn-xs btnDelete' title='Delete'><i class='fa fa-trash-o'></i></a></td><tr>" ; }
@: <text>@row</text>
@:$("#myTable").eq(@i++).after(@row);
}
您__can't__使用__Client Side__ JavaScript变量'itemNSelected'当__SERVER Side__代码呈现逻辑即'如果(itemRSelected == p.RowId && itemNSelected = = p.NamePix)'。为什么不能使用jQuery Ajax实现它? – Satpal
建议你看看答案[这里](http://stackoverflow.com/questions/29161481/post-a-form-array-without-successful/29161796#29161796)和[这里](http:// stackoverflow。 com/questions/28019793/submit-same-partial-view-called-multiple-times-data-to-controller/28081308#28081308)动态添加集合对象到视图 –
@Satpal,我试图避免服务器之旅我希望在第一次查看旅程本身时,我可以在客户端拥有所有模型数据。 – AKS