1
votes

I have a tabstrip that is dynamically populated with a set of partial views. Each of these partial views is an entry form, and some of them have differing Entity Framework data models behind them.

I would like to POST the model to the server with two arguments (a targeted tab index and the model data) whenever a different tab is selected. (To save the tab data)

My issue is that clicking on the tab links seems to be a 'get' action rather than a 'post' action, and I'm having trouble figuring out how to submit data both comprehensive and isolated enough. (comprehensive being the model and isolated being the model associated with a PARTICULAR partial view) I assume I could use JQuery to find and execute the click method of update buttons on the partial view, but that wouldn't preserve a target index.

Is the best method to find a way to uniquely identify the form itself and subsequently post it? Anyone have a hint for me here?

2

2 Answers

0
votes

I am not sure what the best method is. What I do is wrap the code in my partial with

@using (Html.BeginForm("Action", "Controller"))
{
 }

and then just having a submit button click event. That posts back just the information from that partial. If you wanted to send multiple partials to the same action then I would use a hidden field that is set when the tabs are clicked and you should be able to pull that index using a Request.Form["FieldName"]. Hopefully that helps.

Edit:

You can also try an ajax call back to the server

$.ajax({
        url: "@Url.Action("Action", "Controller")",
        type: 'post',
        data: {id: 'hiddenfield', data: 'data', etc},
        dataType: 'json',
        contentType: "application/json",
        success: function (result) {
            (do something)
        }
});

to send the model this way you will need to add those fields to the data row. If there is a lot of data I would recommend stringifying it. You can put this call in the submit button click events.

0
votes

Use ajax call as mentioned. It does not matter whether the element is on parent or partial page. Once the html is rendered, any element on the DOM can be referenced.