C# MVC 5 - How To Get a Table In a Partial View

816 views Asked by At

I'm trying to make a HTML table with a checkbox column where this checkbox column is from a ViewModel:

public string FirstName ...
public string LastName ...
public bool Checked ...

I want to get the List<ViewModel> and pass it to the controller, using a Partial View, to verify the checked columns, because I want to delete the checked lines.

If I wanted to get the checked columns in the same controller, I do, but in a different controller, I don't. In my case, this 'Partial View' is a BS Modal.

1

There are 1 answers

2
beautifulcoder On

What you need is a partial rendered through Ajax. You call the action method from a modal using load and POST the form data so it removes checked lines. You can call any controller you need from this, all you need is:

$('#target').load('@Html.Url("Action", "Controller")');

And on submit:

$('#targetform').submit(function (e) {
    var data = JSON.stringify($(e.currentTarget).serialize());
    $.post('@Html.Url("Action", "Controller")', data, function (html) {
        $('#target').html(html);
    });
    e.preventDefault();
});