Reputation: 3515
let's say that I have grid table which should be populated with data on user click. Request should be sent over ajax and returned data over json. I want to use asp.net mvc3 and jQuery.
My question is how to populate div id with returned json data, how can I recognize targed div and populate with data in that div using jQuery?
Upvotes: 0
Views: 527
Reputation: 31
Could you not use an Ajax.ActionLink that returns a partial view to a specific div with an ID?
In the view
@Ajax.ActionLink("linkText", "action", new AjaxOptions { HttpMethod = "GET", UpdateTargetId = "divContainerId" })
<div id="divContainerId"></div>
In the controller
[HttpGet]
public PartialViewResult action()
{
var jsonData = getData();
return PartialView("_partialView", jsonData);
}
Upvotes: 0
Reputation: 6524
So far as div is considered, you can give it an id and later you will be able to access the element using GetElementbyId javascript function.
For the table elements, You have multiple choices.
Do not code a static table. instead, add elements to dom using jquery or javascript. This way, you will be able to iterate through xml and add relevant rows and columns dynamically.
Code the table in html statically, assign it an id and then access all the cells using next sibling, previous sibling etc relations between cells,
and lastly
Upvotes: 2