0
$("#@ViewBag.PageGroupID").append(data);

现在ViewBag.PageGroupID在运行时返回 div 的 id。如果我想在 div 中附加数据(我将在运行时获得的 id)怎么办。我该如何实现呢?

$('#btnPageElementClick').click(function () { 
   var flag = false; 
   var b; 
   $.ajax({ type: 'GET', url: '/ScriptedTestCase/pageElementPV/' +     $('#PageElements').val(), data: null, 
    success: function (data) 
    { 
       $("#@ViewBag.PageGroupID").append(data); //where divID is the id of the div you append the data. 
    } 
   }); 
return false; 
});
4

1 回答 1

0

确保在呈现包含您显示的脚本的视图的控制器操作中,您实际设置了以下数据:

ViewBag.PageGroupID = "someDivId";

另请注意,在 HTML 中,id 不能以数字开头。

于 2012-08-14T16:12:31.367 回答