0
我對處理請求的方法是能使用幫助確定500(內部服務器錯誤)的源這裏
[HttpPost]
public ActionResult SubmitNew (SolutionSubmission SS)
{
// Going to move this to model later ..
using (SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["LocalJsPracticeDb"].ConnectionString))
{
SqlCommand cmd = new SqlCommand("AddSolution", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@problem_id", SS.ProblemId);
cmd.Parameters.AddWithValue("@solver", SS.Solver);
cmd.Parameters.AddWithValue("@solution_code", SS.SolutionCode);
cmd.Parameters.AddWithValue("@test_code", SS.TestCode);
/*
cmd.Parameters.AddWithValue("@problem_id", 1);
cmd.Parameters.AddWithValue("@solver", "Jeff");
cmd.Parameters.AddWithValue("@solution_code", "<span>Hehe</span>");
cmd.Parameters.AddWithValue("@test_code", "<p>Yo</p>"); */
con.Open();
cmd.ExecuteNonQuery();
}
return Json(new { success = true }) ; // TEST
}
// Going to move this to model later ...
public class SolutionSubmission
{
public int ProblemId { get; set; }
public string Solver { get; set; }
public string SolutionCode { get; set; }
public string TestCode { get; set; }
}
,我打電話與
$('#submit-solution').click(function() {
var rowData = {
ProblemId : $('input[name="problem_id"]').val(),
Solver : $('input[name="solver"]').val(),
SolutionCode: $('#solution').html(),
TestCode : $('#testfuncs').html()
};
console.log(rowData); // TEST
$.ajax({
url: 'SubmitNew',
method: 'POST',
data: rowData,
success: function (retobj) {
// ...
},
error: function () {
// ...
}
})
});
要求我驗證過rowData
是在我的測試案例中有效:它是(字符串)
{"ProblemId":"1","Solver":"adas","SolutionCode":"\n\n <div class=\"CodeMirror cm-s-default\"><div style=\"overflow: hidden; position: relative; width: 3px; height: 0px; top: 4px; left: 4px;\"><textarea autocorrect=\"off\" autocapitalize=\"off\" spellcheck=\"false\" style=\"position: absolute; padding: 0px; width: 1000px; height: 1em; outline: none;\" tabindex=\"0\"></textarea></div><div class=\"CodeMirror-vscrollbar\" cm-not-content=\"true\"><div style=\"min-width: 1px; height: 0px;\"></div></div><div class=\"CodeMirror-hscrollbar\" cm-not-content=\"true\"><div style=\"height: 100%; min-height: 1px; width: 0px;\"></div></div><div class=\"CodeMirror-scrollbar-filler\" cm-not-content=\"true\"></div><div class=\"CodeMirror-gutter-filler\" cm-not-content=\"true\"></div><div class=\"CodeMirror-scroll\" tabindex=\"-1\"><div class=\"CodeMirror-sizer\" style=\"margin-left: 0px; margin-bottom: -23px; border-right-width: 7px; min-height: 48px; min-width: 253.208px; padding-right: 0px; padding-bottom: 0px;\"><div style=\"position: relative; top: 0px;\"><div class=\"CodeMirror-lines\"><div style=\"position: relative; outline: none;\"><div class=\"CodeMirror-measure\"><span><span></span>x</span></div><div class=\"CodeMirror-measure\"></div><div style=\"position: relative; z-index: 1;\"></div><div class=\"CodeMirror-cursors\"><div class=\"CodeMirror-cursor\" style=\"left: 4px; top: 0px; height: 20px;\"> </div></div><div class=\"CodeMirror-code\"><pre class=\" CodeMirror-line \"><span style=\"padding-right: 0.1px;\"><span class=\"cm-keyword\">function</span> <span class=\"cm-def\">myScript</span>(){<span class=\"cm-keyword\">return</span> <span class=\"cm-number\">100</span>;}</span></pre><pre class=\" CodeMirror-line \"><span style=\"padding-right: 0.1px;\"><span cm-text=\"\"></span></span></pre></div></div></div></div></div><div style=\"position: absolute; height: 7px; width: 1px; top: 48px;\"></div><div class=\"CodeMirror-gutters\" style=\"display: none; height: 308px;\"></div></div></div>","TestCode":"\n\n <div class=\"CodeMirror cm-s-default\"><div style=\"overflow: hidden; position: relative; width: 3px; height: 0px; top: 4px; left: 4px;\"><textarea autocorrect=\"off\" autocapitalize=\"off\" spellcheck=\"false\" style=\"position: absolute; padding: 0px; width: 1000px; height: 1em; outline: none;\" tabindex=\"0\"></textarea></div><div class=\"CodeMirror-vscrollbar\" cm-not-content=\"true\"><div style=\"min-width: 1px; height: 0px;\"></div></div><div class=\"CodeMirror-hscrollbar\" cm-not-content=\"true\"><div style=\"height: 100%; min-height: 1px; width: 0px;\"></div></div><div class=\"CodeMirror-scrollbar-filler\" cm-not-content=\"true\"></div><div class=\"CodeMirror-gutter-filler\" cm-not-content=\"true\"></div><div class=\"CodeMirror-scroll\" tabindex=\"-1\"><div class=\"CodeMirror-sizer\" style=\"margin-left: 0px; margin-bottom: -23px; border-right-width: 7px; min-height: 48px; min-width: 253.208px; padding-right: 0px; padding-bottom: 0px;\"><div style=\"position: relative; top: 0px;\"><div class=\"CodeMirror-lines\"><div style=\"position: relative; outline: none;\"><div class=\"CodeMirror-measure\"></div><div class=\"CodeMirror-measure\"></div><div style=\"position: relative; z-index: 1;\"></div><div class=\"CodeMirror-cursors\"><div class=\"CodeMirror-cursor\" style=\"left: 4px; top: 0px; height: 20px;\"> </div></div><div class=\"CodeMirror-code\"><pre class=\" CodeMirror-line \"><span style=\"padding-right: 0.1px;\"><span class=\"cm-keyword\">function</span> <span class=\"cm-def\">myScript</span>(){<span class=\"cm-keyword\">return</span> <span class=\"cm-number\">100</span>;}</span></pre><pre class=\" CodeMirror-line \"><span style=\"padding-right: 0.1px;\"><span cm-text=\"\"></span></span></pre></div></div></div></div></div><div style=\"position: absolute; height: 7px; width: 1px; top: 48px;\"></div><div class=\"CodeMirror-gutters\" style=\"display: none; height: 308px;\"></div></div></div>"}
不過,由於某種原因,我得到了50 0(內部服務器錯誤)。我得到了同樣的錯誤,當我在
/*
cmd.Parameters.AddWithValue("@problem_id", SS.ProblemId);
cmd.Parameters.AddWithValue("@solver", SS.Solver);
cmd.Parameters.AddWithValue("@solution_code", SS.SolutionCode);
cmd.Parameters.AddWithValue("@test_code", SS.TestCode);
*/
cmd.Parameters.AddWithValue("@problem_id", 1);
cmd.Parameters.AddWithValue("@solver", "Jeff");
cmd.Parameters.AddWithValue("@solution_code", "<span>Hehe</span>");
cmd.Parameters.AddWithValue("@test_code", "<p>Yo</p>");
因此也有一些問題,我不具有與方法的身體做SubmitNew
方法替代。任何想法可能是錯的?
您是否驗證過連接字符串在代碼之外是否正確? – Taegost
爲什麼不在try catch中打包並調試它? –
您是否嘗試過附加調試器或記錄異常? – Rhumborl