C# 在通过JSON时获取方法的参数
我调用的方法如下:C# 在通过JSON时获取方法的参数,c#,.net,json,asp.net-mvc-4,C#,.net,Json,Asp.net Mvc 4,我调用的方法如下: public JsonResult RenderTo_Observation(string AccountID) { try { return Json(new { redirectUrl = Url.Action("Observation", "PP", AccountID), isRedirect = true }); } catch (Ex
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创建具有正确名称的参数