[英]Getting parameter for method when passed through JSON
我正在调用方法如下:
public JsonResult RenderTo_Observation(string AccountID)
{
try
{
return Json(new
{
redirectUrl = Url.Action("Observation", "PP", AccountID),
isRedirect = true
});
}
catch (Exception)
{
throw;
}
}
我在PP控制器中调用观察方法,其定义如下:
public ActionResult Observation(string AccountID)
{
ViewBag.AccountID = AccountID;
return View();
}
我在传递accountid参数,正如我们在其中看到的那样:
redirectUrl = Url.Action("Observation", "PP", AccountID)
为此,我确保AccountID具有所需的值。
但是当通过它调用观察函数时,
它没有像过去一样显示我的AccountID参数值。
每当调用函数时,它向我显示null。
上面的代码有什么错误???
请帮我。
您需要将操作参数作为对象传递:
redirectUrl = Url.Action("Observation", "PP", new { AccountID })
这使UrlHelper可以创建具有正确名称的参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.