locked
GET AND POST IN MVC RRS feed

  • Question

  • User103964254 posted

    I have a question about MVC with c #, I have a page which I call from the column of a table executing an ajax function, this works well for me, but when I reload the page with a get method, the data disappears. I need the data to be filled again if I refresh the page

    I need to trigger a get?

    this is my code of my js file

    var codProject= $('#codProject').val();
    var action= $('#action').val();
    var fnEditar = function (codProject) {
        var params = {
            codProject: codProject,
            action:"Edit"
        };
        var url = urlContent + "Projects/Register?codProject=codProject&action=action";
        getFormularioPost(params, url);
        
    }
        getFormularioPost= function (params, url) {
            var form = document.createElement("form");
            document.body.appendChild(form);
            form.method = "POST";
            form.action = url;
    
            for (var key in params) {
                var hiddenField = document.createElement('input');
                hiddenField.setAttribute('type', 'hidden');
                hiddenField.setAttribute('name', key);
                hiddenField.setAttribute('value', params[key]);
    
                form.appendChild(hiddenField);
            }
            form.submit();
        };

    this how mi url look

    http://localhost/Projects/Register?codProject=codProject&action=action

    PD. How can I upload images to the forum?

    Tuesday, September 24, 2019 2:22 PM

All replies

  • User197322208 posted

    I need to trigger a get?

    A GET  does not submit fields ( a POST does)

    If you want get, embed all fields in the query string , not in 

    for (var key in params) {
                var hiddenField = document.createElement('input');

    Tuesday, September 24, 2019 3:53 PM