从JSON返回其他参数

时间:2017-02-25 19:27:07

标签: c# html json

我希望从控制器返回一个JSON响应,其中还包含从其返回的persons name

目前,如果操作成功与否,JSON将返回JsonRequestBehavior.AllowGet

来自控制器的C#代码:

 return Json(true, JsonRequestBehavior.AllowGet);

注意:在控制器中,我想要包含一个返回登录用户名的额外参数。我该如何编码?

前端:

$.ajax({
    url: "/Person/Logged",
    type: "POST",
    data: formData,

    contentType: false,
    processData: false,
    success: function (data) {
      alert("person logged in is ? ");
   }
);

2 个答案:

答案 0 :(得分:0)

您可以尝试返回

import QtQuick 2.0
import QtQuick.Window 2.0
import QtQuick.Controls 2.0
Window {
    width: 1024
    height: 800
    visible: true

    ListView {
        width: 400
        height: 800

        model: ListModel {
            ListElement { projectID: 0; manager: 'I'; sponsor: 'mom' }
            ListElement { projectID: 1; manager: 'YOU'; sponsor: 'dad' }
            ListElement { projectID: 1; manager: 'HE'; sponsor: 'auntie' }
        }

        delegate: SwipeDelegate {
            id: projectSwipeDelegate
            width: parent.width
            // height: <--- provide a height, if the contentItem does not provide it.
            contentItem: Row{ // <--- Add your content as contentItem.
                id: rowProjectDelegate
                anchors.horizontalCenter: parent.horizontalCenter
                width: parent.width
                Column {
                    id: column
//                    anchors.horizontalCenter: parent.horizontalCenter <--- Don't do that!
                    width: parent.width
                    Rectangle{ // If you don't want to have them in a column, they can't be siblings. If you want to, then you should.
                        height: 10
                        width: 250
                        color: "red"

                        Rectangle {
                            height: 10
                            width: 200
                            color: "blue"
                        }
                    }
                    Label {
                        id: projectID_text
                        text: "Project ID: " + projectID
                        font.pointSize: 20
                        font.weight: Font.Black
                        color: "white"
                    }
                    Label {
                        id: manager_text
                        text: 'Manager: ' + manager + "  Sponsor: " + sponsor
//                        anchors.top: projectID_text.bottom <--- Don't do that!
                        font.weight: Font.Thin
                        color: "lightgrey"
                    }
                }
            }
        }
    }
}

和ajax

return Json(new {name="myname"}, JsonRequestBehavior.AllowGet);

答案 1 :(得分:0)

return Json("{'success': true, 'name': 'bob chod'}", JsonRequestBehavior.AllowGet);