0

I have two pages, a employee edit page and a view all employe table page.

I want to be on the view all employee table page and if the users clicks a row, I want to submit to the controller the employee id and then load the employee edit page. I can get all the information needed to do this but can't seem to find a way to submit the page to the controller with the additional parameter.

Any ideas???

EDIT

Essentially what I want to do is if the click a row in the datatable for employee id 5, I want to say submit the form to /LoadEmployeeInfo/Employee with employee id 5 as the parameter. Can this be done with javascript????

1 Answer 1

2

To do this you just need to get the EmployeeId and then can just call the link

 $('#employeeTable tbody tr').click(function ()
 {
    var EmployeeId =$("td:first", this).text();

    window.location = "/yourControllerName/yourActionMethodName/" + EmployeeId; 
  });

your action method should have id as method parameter

public ActionResult YourActionMethod(int id)
{
       int employeeId = id;

       // Rest of your code
}
Sign up to request clarification or add additional context in comments.

4 Comments

Im using a data-table and I get the value for what was clicked from this: $('#employeeTable').on('click', 'tbody tr', function() { var data = [{ name: "employeeId", value: $("td:first", this).text() }]; I want to submit the form to a url and give it the data value as the paramter.
it gives me this error: The parameters dictionary contains a null entry for parameter 'employeeId' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult LoadEmployeeData(Int32)
I had to use: "/yourControllerName/yourActionMethodName?employeeId=" + employeeId
I went on the assumption that the action method received the id parameter as I have updated the answer to show the action method. However if you prefer to have the link that, that is correct also. Please tick if it is the correct answer. Thanks :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.