Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在通过JSON时获取方法的参数_C#_.net_Json_Asp.net Mvc 4 - Fatal编程技术网

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创建具有正确名称的参数