How to access JsonResult data when testing in ASP.NET MVC

前端 未结 3 1713
北海茫月
北海茫月 2020-12-17 18:02

I have this code in C# mvc Controller:

[HttpPost]
    public ActionResult Delete(string runId)
    {
        if (runId == \"\" || runId == null)
                 


        
3条回答
  •  情歌与酒
    2020-12-17 18:12

    You can use like this - the result will be the expected object definition. So in case of success, your success flag will be TRUE otherwise false and if false then you should expect that the error property will be updated with the error message.

            JsonResult jsonResult = oemController.List() as JsonResult;
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            Result result = serializer.Deserialize(serializer.Serialize(jsonResult.Data));
    
            public class Result 
            {
                public bool success ;
                public string error;
            }
    

提交回复
热议问题