Ajax调用 -
$.ajax({
type: "POST",
url: configMap.sitePath + "api/Quiz/" + quizResponse.quizId,
data: JSON.stringify(quizResponse),
success: function(data) {
var resultid = data.data.quizInstanceId;
var resultresponse = data.data;
window.location.href = "supply-chain-pressure/ScptResult/" + resultresponse;
}
控制器方法 -
public ActionResult ScptResult(QuizResult resultresponse)
{
// Do something
return View();
}
路线 -
routes.MapRoute(
name: "SupplyChainPressureResult",
//url: "supply-chain-pressure/ScptResult/{resultid}",
url: "supply-chain-pressure/ScptResult/{resultresponse}",
defaults: new { controller = "SupplyChainPressure", action = "ScptResult" }
);
class -
public class QuizResult
{
public int quizInstanceId { get; set; }
public string WeakestLinkCode { get; set; }
public string WeakestLinkDescription { get; set; }
public decimal PercentageOfUsers { get; set; }
public IEnumerable<OverallResult> OverallResults { get; set; }
}
但由于某些原因,resultresponse
在控制器方法中为空。请有人帮忙吗。我们需要将data.data
(resultresponse
)传递给控制器方法。
答案 0 :(得分:0)
谢谢每一个人的帮助。我只使用一个参数,然后重定向到一个控制器方法,为我做的事情 -
$.ajax({
type: "POST",
url: configMap.sitePath + "api/Quiz/" + quizResponse.quizId,
data: JSON.stringify(quizResponse),
success: function (data) {
var resultId = data.data.quizInstanceId;
window.location.href = configMap.sitePath + 'Result-Display/Index/' + resultId;
},