• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# JsonResponse类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中JsonResponse的典型用法代码示例。如果您正苦于以下问题:C# JsonResponse类的具体用法?C# JsonResponse怎么用?C# JsonResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JsonResponse类属于命名空间,在下文中一共展示了JsonResponse类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: Crear

        public virtual JsonResult Crear(CategoriaProducto entidad)
        {
            var jsonResponse = new JsonResponse { Success = false };

            if (ModelState.IsValid)
            {
                try
                {
                    entidad.UsuarioCreacion = UsuarioActual.IdUsuario.ToString();
                    entidad.UsuarioModificacion = UsuarioActual.IdUsuario.ToString();

                    if (entidad.CAT_NombreIngles == null)
                        entidad.CAT_NombreIngles = "";
                    if (entidad.CAT_Descripcion == null)
                        entidad.CAT_Descripcion = "";
                    entidad.CAT_IndicadorArea = "A"; // cambiar 22/01/2013

                    CategoriaProductoBL.Instancia.Add(entidad);

                    jsonResponse.Success = true;
                    jsonResponse.Message = "Se Proceso con éxito";
                }
                catch (Exception ex)
                {
                    logger.Error(string.Format("Mensaje: {0} Trace: {1}", ex.Message, ex.StackTrace));
                    jsonResponse.Message = "Ocurrio un error, por favor intente de nuevo o más tarde.";
                }
            }
            else
            {
                jsonResponse.Message = "Por favor ingrese todos los campos requeridos";
            }
            return Json(jsonResponse, JsonRequestBehavior.AllowGet);
        }
开发者ID:JolevqSAC,项目名称:Interv2,代码行数:34,代码来源:CategoriaProductoController.cs


示例2: Crear

        public virtual JsonResult Crear(CentroCosto entidad)
        {
            var jsonResponse = new JsonResponse { Success = false };

            if (ModelState.IsValid)
            {
                try
                {
                    entidad.UsuarioCreacion = UsuarioActual.IdUsuario.ToString();
                    entidad.UsuarioModificacion = UsuarioActual.IdUsuario.ToString();
                    CentroCostoBL.Instancia.Add(entidad);

                    jsonResponse.Success = true;
                    jsonResponse.Message = "Se Proceso con éxito";
                }
                catch (Exception ex)
                {
                    logger.Error(string.Format("Mensaje: {0} Trace: {1}", ex.Message, ex.StackTrace));
                    jsonResponse.Message = "Ocurrio un error, por favor intente de nuevo o más tarde.";
                }
            }
            else
            {
                jsonResponse.Message = "Por favor ingrese todos los campos requeridos";
            }
            return Json(jsonResponse, JsonRequestBehavior.AllowGet);
        }
开发者ID:JolevqSAC,项目名称:Interv2,代码行数:27,代码来源:CentroCostoController.cs


示例3: BuscarIDCargo

        public virtual JsonResult BuscarIDCargo(string nombre)
        {
            var jsonResponse = new JsonResponse {Success = false};
            if (ModelState.IsValid)
            {
                try
                {
                    string[] name = nombre.Split('-');
                    //var lista = (Cargo)TrabajadorBL.Instancia.Search(name.ElementAt(1).Trim()).SingleOrDefault();
                    var lista = (Cargo)TrabajadorBL.Instancia.Search(nombre.Trim()).SingleOrDefault();

                    jsonResponse.Data = lista.IDCargo;
                    jsonResponse.Success = true;
                }
                catch (Exception ex)
                {
                    jsonResponse.Success = false;
                    return Json("ERROR - Vuelva a cargar la Página", JsonRequestBehavior.AllowGet);
                }
            }
            else
            {
                jsonResponse.Message = "Por favor ingrese todos los campos requeridos";
            }
            return Json(jsonResponse, JsonRequestBehavior.AllowGet);
        }
开发者ID:JolevqSAC,项目名称:Interv2,代码行数:26,代码来源:TrabajadorController.cs


示例4: AppendFile

    public static JsonResponse AppendFile(string path)
    {
        JsonResponse response = new JsonResponse()
        {
            Data = string.Empty,
            Success = false,
            Message = ""
        };
        //check rights
        if (!Security.IsAuthorizedTo(Rights.CreateNewPosts))
        {
            response.Success = false;
            response.Message = "Access denied";
            return response;
        }

        var file = BlogService.GetFile(path);
        if (file != null)
        {
            if (file.IsImage)
            {
                var imagePath = string.Format("<img src=\"{0}\" />", file.AsImage.ImageUrl);
                response.Success = true;
                response.Data = imagePath;
            }
            else
            {
                var filePath = string.Format("<p><a href=\"{1}\" >{0}</a></p>", file.FileDescription, file.FileDownloadPath);
                response.Success = true;
                response.Data = filePath;
            }
        }
        return response;
    }
开发者ID:Cycli,项目名称:Cycli,代码行数:34,代码来源:AjaxFileManager.aspx.cs


示例5: GetRegions

        public ActionResult GetRegions(string id)
        {
            string regionid = Request.Form["regionid"];

            JsonResponse result = new JsonResponse();            
            Country c = Country.FindByBvin(id);
            if ((c != null))
            {
                StringBuilder sb = new StringBuilder();
                result.Regions = string.Empty;

                foreach (Region r in c.Regions)
                {
                    sb.Append("<option ");
                    if (r.Abbreviation == regionid)
                    {
                        sb.Append(" selected=\"selected\" ");
                    }
                    sb.Append(" value=\"" + r.Abbreviation + "\">" + r.Name + "</option>");
                }

                result.Regions = sb.ToString();
            }

            return new JsonResult() { Data = result };
        }
开发者ID:appliedi,项目名称:MerchantTribe,代码行数:26,代码来源:EstimateShippingController.cs


示例6: Edit

        public ActionResult Edit(int boardId, Competitor updatedCompetitor)
        {
            var board = _repository.GetBoardById(boardId);
            var competitor = _repository.GetCompetitorByName(boardId, updatedCompetitor.Name);
            var response = new JsonResponse<bool>();

            if (competitor == null)
            {
                response.Message = "Competitor not found";
                response.Error = true;
            }
            else if (!competitor.CanEdit(board, User.Identity.Name))
            {
                response.Message = "Invalid authority";
                response.Error = true;
            }
            else
            {
                // Just update status for now (owner only can change status)
                if(board.IsOwner(User.Identity.Name))
                    competitor.Status = updatedCompetitor.Status;

                _repository.CommitChanges();
                response.Result = true;
            }

            return (Json(response));
        }
开发者ID:kellyelton,项目名称:ChallengeBoard,代码行数:28,代码来源:CompetitorsController.cs


示例7: Should_fail_to_return_xml_body_on_non_xml_response

        public void Should_fail_to_return_xml_body_on_non_xml_response()
        {
            var response = new JsonResponse<Model>(new Model() { Dummy = "Data" });
            var context = new NancyContext() { Response = response };

            Assert.Throws<InvalidOperationException>(() => context.XmlBody<Model>());
        }
开发者ID:rmueller,项目名称:Nancy,代码行数:7,代码来源:ContextExtensionsTests.cs


示例8: EnableCors

 public static void EnableCors(this IPipelines pipelines, CorsConfiguration corsConfiguration)
 {
     pipelines.AfterRequest.AddItemToEndOfPipeline(ctx =>
     {
         UpdateResponseHeaders(ctx.Request, ctx.Response, corsConfiguration);
     });
     pipelines.OnError.AddItemToEndOfPipeline((ctx, exception) =>
     {
         if (exception == null)
         {
             // Nothing to serialize, just return default 500 response
             return HttpStatusCode.InternalServerError;
         }
         Response response;
         if (ctx.Request.Headers.Accept.Any(x => x.Item1.ToLowerInvariant().Contains("application/json")))
         {
             // Return the exception detail as JSON
             response = new JsonResponse(new ExceptionDetailObject(exception),
                 new DefaultJsonSerializer()) {StatusCode = HttpStatusCode.InternalServerError};
         }
         else
         {
             // Return the exception message as text/plain
             response = new TextResponse(HttpStatusCode.InternalServerError, exception.Message);
         }
         UpdateResponseHeaders(ctx.Request, response, corsConfiguration);
         return response;
     });
 }
开发者ID:jaensen,项目名称:BrightstarDB,代码行数:29,代码来源:CorsPipelinesExtension.cs


示例9: Upload

        public string Upload(HttpPostedFileBase file, FormCollection forms)
        {
            var jsonResponse = new JsonResponse { Success = false };
            try
            {
                var content = new byte[file.ContentLength];
                file.InputStream.Read(content, 0, file.ContentLength);
                var indexOfLastDot = file.FileName.LastIndexOf('.');
                var extension = file.FileName.Substring(indexOfLastDot + 1, file.FileName.Length - indexOfLastDot - 1);
                var name = file.FileName.Substring(0, indexOfLastDot);

                var fileUpload = new ImageFile
                {
                    Id = string.Format("_{0}", DateTime.Now.ToString("M_dd_yyyy_H_M_s")),
                    Name = name,
                    DirectoryPath = ConfigurationManager.AppSettings["TempFilePath"],
                    ApplicationPath = System.Web.HttpContext.Current.Request.PhysicalApplicationPath,
                    Extension = extension,
                    Data = content
                };

                jsonResponse.Data = fileUpload.RelativePath;
                jsonResponse.Success = true;
            }
            catch (Exception ex)
            {
                logger.Error(string.Format("Mensaje: {0} Trace: {1}", ex.Message, ex.StackTrace));
                jsonResponse.Message = "Ocurrio un error, por favor intente de nuevo o más tarde.";
            }

            return JsonConvert.SerializeObject(jsonResponse);
        }
开发者ID:JolevqSAC,项目名称:Interv2,代码行数:32,代码来源:HomeController.cs


示例10: GetUploadStatus

 public static JsonResponse GetUploadStatus(string qid)
 {
     var j = new JsonResponse();
     // try and turn the id into a guid
     Guid id;
     if (!Guid.TryParse(qid, out id)) {
         j.Message = "Id not a valid Guid.";
         j.Error = 1;
         return j;
     }
     if(!Core.UploadStatuses.ContainsKey(id)) {
         j.Message = "Upload does not exist or status has expired.";
         j.Error = 2;
         return j;
     }
     var u = Core.UploadStatuses[id];
     j.Add("BytesRead", u.BytesRead);
     j.Add("BytesTotal", u.BytesTotal);
     j.Add("Complete", u.Complete);
     j.Add("CurrentFile", u.CurrentFile);
     j.Add("Id", u.Id);
     j.Add("LastUpdated", u.LastUpdated);
     j.Add("Message", u.Message);
     j.Add("StartedOn", u.StartedOn);
     return j;
 }
开发者ID:CorbinDallas,项目名称:Oda,代码行数:26,代码来源:GetUploadStatusJson.cs


示例11: Upload

 public static JsonResponse Upload(string targetPath, IList<UploadedFile> files)
 {
     var j = new JsonResponse();
     if(files.Count>1) {
         j.Error = 1;
         j.Message = "FileManager.Upload only supports one file at a time.  Use FileManager.UploadFiles instead.";
         return j;
     }
     if (files.Count == 0) {
         j.Error = 2;
         j.Message = "Source file is missing from upload request.";
         return j;
     }
     try {
         targetPath = targetPath.Replace("~\\", Core.BaseDirectory) + files[0].OriginalFileName;
         if(File.Exists(targetPath)) {
             File.Delete(targetPath);
         }
         File.Move(files[0].Path, targetPath);
     }catch(Exception e) {
         j.Error = e.Message.GetHashCode();
         j.Message = e.Message;
         return j;
     }
     j.Error = 0;
     j.Message = "File uploaded successfully.";
     return j;
 }
开发者ID:CorbinDallas,项目名称:Oda,代码行数:28,代码来源:FileManager.cs


示例12: Create

        public ActionResult Create(PostViewModel post)
        {
            var response = new JsonResponse<PostViewModel>();
            var newPost = new Post();

            try
            {
                newPost.Board = _repository.GetBoardById(post.BoardId);
                newPost.Owner = _repository.GetCompetitorByUserName(post.BoardId, User.Identity.Name);
                newPost.Body = post.Body;

                _repository.Add(newPost);
                _repository.CommitChanges();

                newPost.Owner.LastViewedPostId = newPost.PostId;
                _repository.CommitChanges();

                response.Result = new PostViewModel(newPost);
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
                response.Error = true;
            }

            return (Json(response));
        }
开发者ID:ANTco,项目名称:ChallengeBoard,代码行数:27,代码来源:DiscussionController.cs


示例13: loginpage

        public string loginpage()
        {
            var jp = new JsonResponse();

            jp.result = true;
            jp.addData(this, "loginpage");

            return jp.ToString();
        }
开发者ID:FuujinTheHacker,项目名称:LoM,代码行数:9,代码来源:AjaxController.cs


示例14: Process

 public void Process(ISemanticProcessor proc, IMembrane membrane, JsonResponse resp)
 {
     resp.Context.Response.StatusCode = resp.StatusCode;
     resp.Context.Response.ContentType = "text/json";
     resp.Context.Response.ContentEncoding = Encoding.UTF8;
     resp.Context.Response.ContentLength64 = resp.Json.Length;
     resp.Context.Response.OutputStream.Write(resp.Json.to_Utf8(), 0, resp.Json.Length);
     resp.Context.Response.Close();
 }
开发者ID:the-wazz,项目名称:clifton,代码行数:9,代码来源:WebResponse.cs


示例15: Should_create_new_wrapper_from_json_response_if_not_already_present

        public void Should_create_new_wrapper_from_json_response_if_not_already_present()
        {
            var response = new JsonResponse<Model>(new Model() { Dummy = "Data" });
            var context = new NancyContext() { Response = response };

            var result = context.JsonBody<Model>();

            result.Dummy.ShouldEqual("Data");
        }
开发者ID:rmueller,项目名称:Nancy,代码行数:9,代码来源:ContextExtensionsTests.cs


示例16: Should_fail_to_return_xml_body_on_non_xml_response

        public void Should_fail_to_return_xml_body_on_non_xml_response()
        {
            var response = new JsonResponse<Model>(new Model() { Dummy = "Data" }, new DefaultJsonSerializer());
            var context = new NancyContext() { Response = response };

            var result = Record.Exception(() => context.XmlBody<Model>());

            result.ShouldNotBeNull();
        }
开发者ID:RobertTheGrey,项目名称:Nancy,代码行数:9,代码来源:ContextExtensionsTests.cs


示例17: ReturnJson

        /// <summary>
        /// Return a Json response to the client app
        /// </summary>
        /// <param name="response">The response object to be stringify and return to client app</param>
        public void ReturnJson(JsonResponse response)
        {
            string output = JsonConvert.SerializeObject(response);

            Response.StatusCode = 200;
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ContentType = "application/json";
            Response.Write(output);
        }
开发者ID:a-fung,项目名称:MangaWeb3,代码行数:13,代码来源:AjaxBase.cs


示例18: Should_create_new_wrapper_from_json_response_if_not_already_present

        public void Should_create_new_wrapper_from_json_response_if_not_already_present()
        {
            // Given
            var response = new JsonResponse<Model>(new Model() { Dummy = "Data" }, new DefaultJsonSerializer());
            var context = new NancyContext() { Response = response };

            // When
            var result = context.JsonBody<Model>();

            // Then
            result.Dummy.ShouldEqual("Data");
        }
开发者ID:nclarence,项目名称:WebAPI.Testing,代码行数:12,代码来源:ContextExtensionsTests.cs


示例19: logout

        public string logout()
        {
            var jp = new JsonResponse();

            if (isLogdin)
                FormsAuthentication.SignOut();
            else
                jp.ex = "not Authenticated";

            jp.result = isLogdin;

            return jp.ToString();
        }
开发者ID:FuujinTheHacker,项目名称:LoM,代码行数:13,代码来源:AjaxController.cs


示例20: Execute

        public JsonResponse Execute(CreateLinkInputModel inputModel)
        {
            var response = new JsonResponse { Success = true };
            var link = new Link
                           {
                               DateAdded = DateTime.Now,
                               OriginalUrl = inputModel.OriginalUrl,
                               ShortenedUrl = _urlShortener.Shorten(inputModel.OriginalUrl)
                           };
            _repository.Insert(link);
            _repository.Save();

            return response;
        }
开发者ID:davidalpert,项目名称:fubulinks,代码行数:14,代码来源:PostHandler.cs



注:本文中的JsonResponse类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# JsonSchema4类代码示例发布时间:2022-05-24
下一篇:
C# JsonRequestBehavior类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap