【问题标题】:Allowing Json Get without using Return(data, JsonRequestBehavior.AllowGet) (To allow GET requests, set JsonRequestBehavior to AllowGet. error)在不使用 Return(data, JsonRequestBehavior.AllowGet) 的情况下允许 Json Get(要允许 GET 请求,请将 JsonRequestBehavior 设置为 AllowGet.error)
【发布时间】:2012-01-05 23:20:51
【问题描述】:

我想在我的 C# 项目中使用 javascript 上传器。 javascript 在母版页中加载,在我希望上传者所在的部分视图中,我有以下代码:

   <a class="upload" href="/Administration/blue/en-gb/Entity/StoreFile/97?Entity=Note&amp;Field=File">uploadfile</a>

但是,当我单击该按钮时,我得到一个“此请求已被阻止,因为在 GET 请求中使用此信息时可能会将敏感信息泄露给第三方网站。要允许 GET 请求,请将 JsonRequestBehavior 设置为 AllowGet。 "错误。同类型的问题可以在here 找到。但是,作为解决方案,给出了以下内容:

 return Json(new { mymsg = "my msg" }, JsonRequestBehavior.AllowGet);

添加 JsonRequestBehavior.AllowGet 可以解决问题。

在调用 PartialView 的 C# ActionResult 中,我想在其中添加此内容,我将其作为返回:

return PartialView("CreateNotePartial", Model);

我也试过了:

<%$.post('/blag/JSON', function (data) {%>
    <a class="upload" href="/Administration/blue/en-gb/Entity/StoreFile/97?Entity=Note&amp;Field=File">uploadfile
        </a>
 <%});%>

但这没有用。

我无法添加 JsonRequestBehavior.AllowGet。如果没有这个 .AllowGet,如何使它工作?

【问题讨论】:

  • 一定要返回局部视图还是json?

标签: c# javascript json


【解决方案1】:

这对我有帮助,也许对其他人也有帮助。

public JsonResult AppleAppSiteAssociation()
{
        string json = "{\"applinks\": {\"apps\": [],\"details\": [] }}";
        JsonResult res = new JsonResult();
        res.Data = json;
        res.JsonRequestBehavior = JsonRequestBehavior.AllowGet;

        return res;
}

【讨论】:

    猜你喜欢
    • 2017-07-01
    • 2019-06-25
    • 2010-12-10
    • 2023-04-02
    • 2015-03-09
    • 1970-01-01
    • 1970-01-01
    • 2019-05-15
    相关资源
    最近更新 更多