asp.net - MVC 4 - 500 error on JSON call -


i have started using vs2012 (yes time). have mvc 4 app.

im making json call data db render in html.

but im getting 500 internal server error can see in fiddler.

im not sure how debug because cant find see c# exception if issue is.

so im calling getrecipe in javascript.

public jsonresult getrecipe(int rid) {      var recipe = _rep.getrecipe(rid);       return json(recipe, jsonrequestbehavior.allowget); } 

my script is

var dataservice = new function () { var servicebase = '/recipes/'     getrecipeslist = function (callback) {         $.getjson(servicebase + 'getrecipeslist', {}, function (data) {             callback(data);         });      };      getrecipe = function (rid, callback) {         $.getjson(servicebase + 'getrecipe', {rid:rid}, function (data) {             callback(data);         });      }; return {     getrecipeslist: getrecipeslist,     getrecipe: getrecipe }; 

} ();

var renderer = new function () { renderlist = function () {     dataservice.getrecipeslist(renderlistdiv); },  renderlistdiv = function (recipes) {     var listdiv = $('#listdiv');     listdiv.html("");     $(recipes).each(function (index) {         var table = '<table>';         table += ('<tr><td><a class="recipelink" href="#recipelist-' + this.recipeid + '">' + this.recipetitle + '</a></td></tr>');         table += '</table>';         listdiv.append(table);     }); },  selectedrecipe = function (anchor) {     var href = $(this).attr("href");     var rid = href.split("-")[1];     dataservice.getrecipe(rid, renderrecipe); };  renderrecipe = function (recipe) {     var recipediv = $('#recipediv');      var html = '<h1>' + recipe.recipetitle + ' (' + recipe.recipeid + ')</h1>';     html += '<h4>preparation time: ' + gettimestring(recipe.preptime) + '</h4>';     html += '<h4>cooking time: ' + gettimestring(recipe.cooktime) + '</h4>';     var count = recipe.ings.length;     var colmax = math.ceil(count / 2);     var colleft = 0;     var colright = colmax;     html += '</br><table id="ingredientstable">';     (colleft = 0; colleft < colmax; colleft++) {         html += '<tr>';         html += '<td>' + recipe.ingredients[colleft].units + ' ' + recipe.ingredients[colleft].measure + ' ' + recipe.ingredients[colleft].ingredientname + '</td>';         if(colright < count)             html += '<td>' + recipe.ingredients[colright].units + ' ' + recipe.ingredients[colright].measure + ' ' + recipe.ingredients[colright].ingredientname + '</td>';         colright += 1;         html += '</tr>';     }     html += '</table>';     html += '<h4>method</h4>';     html += '<p>' + recipe.method + '</p>';      recipediv.html(html);      numingredients = 0;     editorform.loadeditor(recipe); };  clearrecipe = function () {     $('#recipediv').html(""); };  gettimestring = function (time) {     if (time < 60)         return time + ' min';     return time / 60 + ' hours' };  changefont = function () {     $('body').css("font-family", "comic sans ms"); };  return {     renderlist: renderlist,     selectedrecipe: selectedrecipe,     changefont: changefont,     clearrecipe: clearrecipe,  }; 

}();

the browser's developer tools might place additional information. in chrome can press f12 bring dev tools window. click on network tab , fire off ajax call. see failed request highlighted in red. if click on see error has been returned mvc.

i have provided screenshot in question: ajax call 'failed load resource : server responded status of 500'


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -