ajax - View not rendering after foreach loop MVC -
goal: attempting populate table based on dropdown list using razor syntax populate table.
summary: passing model view , looping thru each object within model. able see objects populated within model when debugging view, however, when page displays, there nil in table , thing displaying dropdown.
question: may problem page rendering?
my view follows:
@model ienumerable<fantasysportsmvc.models.playerdetails> @{ viewbag.title = "position"; } <h2>position</h2> <body> <div> @html.dropdownlist("ddltournaments",(ienumerable<selectlistitem>)viewbag.tournaments, new { id="ddltournament", name="ddltournament"}) </div> <div> <input type="button" id="btngetdata" value="show me stuff, yo!" /> </div> <div id="results"> </div> <table id="tbdetails"> @if(model != null) { <tbody> @foreach (var player in model) { <tr> <td>@player.lastname</td> <td>@player.firstname</td> <td>@player.position</td> </tr> } </tbody> } </table> </body> <script type="text/javascript"> function sendtournamentid() { var info = json.stringify({ id : $("#ddltournament option:selected").val()}); $.ajax({ url: '/leaderboard/position', type: 'post', datatype: 'json', data: data, contenttype: 'application/json; charset=utf-8', success: function (result) { //return json.stringify($("#ddltournament option:selected").val()); $("#ddltournament option:selected").val(result.d.id); } }); } $(function () { $('#btngetdata').click(sendtournamentid); }); </script>
my controller follows:
public class leaderboardcontroller : controller { public actionresult position() { viewbag.tournaments = gettournamentdetailsselectlist(); homecoming view(); } [httppost] public actionresult position(string id) { viewbag.tournaments = gettournamentdetailsselectlist(); var tournamentid = id; var url = constructleaderboardurl(tournamentid); var xmltojsonurl = convertxmltojson(url); list<playerdetails> details = binddatatableplayerdetails(xmltojsonurl); homecoming view(details); } } private static list<playerdetails> binddatatableplayerdetails(string url) { dtattributelist = new datatable(); var details = new list<playerdetails>(); seek { //convertxmltojson(url); // build datatable dtattributelist.columns.add("last name", typeof(string)); dtattributelist.columns.add("first name", typeof(string)); dtattributelist.columns.add("position", typeof(string)); // add together rows datatable json (int = 0; < doc.getelementsbytagname("player").count; i++) { dtattributelist.rows.add( doc.getelementsbytagname("player").item(i).attributes["last_name"].value, doc.getelementsbytagname("player").item(i).attributes["first_name"].value, doc.getelementsbytagname("player").item(i).attributes["position"].value); } // add together rows datatable playerdetails foreach (datarow row in dtattributelist.rows) { var player = new playerdetails(); player.lastname = row["last name"].tostring(); player.firstname = row["first name"].tostring(); player.position = row["position"].tostring(); details.add(player); } } grab (exception e) { throw new exception(); } homecoming details; }
ajax asp.net-mvc razor
No comments:
Post a Comment