Using javascript to call controller methond in mvc

Posted by Christian Thoresson Dahl on Stack Overflow See other posts from Stack Overflow or by Christian Thoresson Dahl
Published on 2012-09-01T21:32:35Z Indexed on 2012/09/01 21:38 UTC
Read the original article Hit count: 226

Filed under:
|
|
|
|

Im trying to make a table row work as a link to another view in my mvc website. Instead of using the standard "Details" link provided by the auto generated table list, I would like to use the table row as a link to the "Details" view instead. So somehow I need to make the row work as a link. Each rom has a unique id that I need to pass on to the controller method. I have tried different solutions but noting happens when I press on the table row...

So far this is what I have:

<script type="text/javascript">
$(document).ready(function(){
    $('#customers tr').click(function () {
        var id = $(this).attr('id');
        $.ajax({
            url: "Customer/Details" + id,
            succes: function () { }
        });
    })
})
</script>

My controller method:

        public ActionResult Details(int id)
    {
        Customer model = new Customer();
        model = this.dbEntities.Customers.Where(c => c.Customer_ID == id).Single();
        return View(model);
    }

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery