Open another view through controller from jQuery?

768 views Asked by At

I have a view with a jQuery Click. I want to send an ID to a controller and open a view.

   j("#jstree_demo_div").on('select_node.jstree', function (e, data) {
            console.log(data.node.a_attr.href); // Node value

            $.ajax({
                type: "GET",
                url: '@Url.Action("FilterCategories", "FileUploads")',
                dataType: "html",
                success: function (data) {
                    /* alert(data); */
                },
                statusCode: {
                    404: function (content) { alert('cannot find resource' + data.node.a_attr.href); },
                    500: function (content) { alert('internal server error' + data.node.a_attr.href); }
                },
                error: function (req, status, errorObj) {
                    // handle status === "timeout"
                    // handle other errors
                }
            });

        });

I can see the page in the alert if I uncomment alert(data); but how do I open my controller and return my view?

My controller

public ActionResult CategoryId(/*int? CategoryId*/) 
{
    //Something with CategoryId
    return View();
}

And I have a view CategoryId in Views folder. Guess I need something more on success: function (data)

1

There are 1 answers

0
Jeremy C. On

I did something similar earlier today and found that this did the trick:

success: function(response){
                document.write(response);
            }