Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
485 views
in Technique[技术] by (71.8m points)

c# - How to pass additional postdata into an add record function - JQGrid - MVC . NET

I am using the JQGrid plugin on an MVC project. I am trying to avoid using 'Session'. I have been able to pass extra postdata into my edit and delete functions, using the serializedata methods from JQGrid.

E.G.

serializeEditData: function (postdata) 
{
    var rowdata = jQuery('#gridId').getRowData(postdata.id);
    return {id: postdata.id, oper: postdata.oper, SomeExtraData: $('#extradata').val()};
}

However, there doesn't appear to be a serializeAddData function. Is there another way to alter the post data for the add method before it is sent?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There are one method editGridRow which implement form editing for both "Edit" and "Add" dialogs. So the same event han`ler serializeEditData can be used in both cases. For example,

$("#list").jqGrid('navGrid','#pager',
    {/*navGrid options*/},
    {/*edit options*/
        serializeEditData: function (postdata) {
            // your implementation of serializeEditData for edit
        }
    },
    {/*add options*/
        serializeEditData: function (postdata) {
            // your implementation of serializeEditData for add
        }
    },
    {/*del options*/},
    {/*search options*/}

/ );

Typically serializeEditData event is very practical if you need convert all the posted data in another format, for example to make JSON serialization. To be able to pass extra postdata parameters you can use editData parameter instead which has the same meaning like postData parameter of jqGrid:

$("#list").jqGrid('navGrid','#pager',
    {/*navGrid options*/},
    {/*edit options*/
     editData: {SomeExtraData: $('#extradata').val()}
    },
    {/*add options*/
     editData: {SomeExtraData: $('#extradata').val()}
    },
    {/*del options*/},
    {/*search options*/}
);

or better in this way (see this answer about the usage of functions as the property of postData):

$("#list").jqGrid('navGrid','#pager',
    {/*navGrid options*/},
    {/*edit options*/
     editData: {SomeExtraData: function() {return $('#extradata').val();}}
    },
    {/*add options*/
     editData: {SomeExtraData: function() {return $('#extradata').val();}}
    },
    {/*del options*/},
    {/*search options*/}
);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...