I am working on a search page which displays a table of results. I want to add some functionality with Javascript. The entire table is encapsulated within a form, and each item on the table has several actions you can perform; One example is Add comment.
I am able to pass all the other form variables correctly as they are static. The issue I am having is being able to pass the ID to the action since it changes for each row of the result. Here is what I have so far (shortened)
Action header:
public ActionResult Create( ........., Int ID);
View:
...
@foreach( var item in Model )
{
...
@Html.ActionLink("Comment", "Create", "Comment", new { ID = Model.ID }, new { onclick = "CommentSubmit(@Model.ID)" })
}
Javascript:
function CommentSubmit(id) {
//What do?
$("#DynForm").attr("action", "/Comment/Create");
$("#DynForm").submit();
};
How can I just Javascript/jQuery to pass in the ID in addition to my other form variables?
Kind of a side question, but do I need stop the original anchor from executing (since my javascript is submitting the form)? How do I do this?